Another pass to a working alpha

This commit is contained in:
Luke Murphy 2020-06-30 01:40:01 +02:00
parent b552a2d3e4
commit d5e54b936a
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC
5 changed files with 36 additions and 8 deletions

View File

@ -0,0 +1,5 @@
# flat-tree 0.0.1a1 (2020-06-30)
## Project Announcements
- The first alpha development release is made!

View File

@ -1,3 +1,9 @@
# pyvarint
[![Build Status](https://drone.autonomic.zone/api/badges/hyperpy/pyvarint/status.svg)](https://drone.autonomic.zone/hyperpy/pyvarint)
## varint, a method of serializing integers using one or more bytes
```sh
$ pip install pyvarint
```

View File

@ -1,10 +1,9 @@
"""Varint encode and decode"""
import sys
from StringIO import StringIO as BytesIO
from io import BytesIO
def encode(number):
def encode(number: int) -> bytes:
"""Encode to varint"""
buf = b""
@ -20,9 +19,10 @@ def encode(number):
return buf
def decode(buf):
def decode(buf: bytes) -> int:
"""Decode to bytes"""
stream = BytesIO(buf)
shift = 0
result = 0
@ -42,7 +42,7 @@ def decode(buf):
return result
def encoding_length(n):
def encoding_length(n: int) -> int:
"""The number of bytes this number will be encoded as."""
N1 = pow(2, 7)
N2 = pow(2, 14)

View File

@ -1 +1,18 @@
# https://github.com/chrisdickinson/varint/blob/master/test.js
from math import floor, pow
from random import sample
from pyvarint import decode, encode, encoding_length
def test_fuzz_test():
ten_rand_ints = sample(range(100), 10)
for rand_int in ten_rand_ints:
encoded = encode(rand_int)
decoded = decode(encoded)
assert decoded == rand_int
def test_encoding_length():
for idx in range(0, 53):
number = floor(pow(2, idx))
assert len(encode(number)) == encoding_length(number)

View File

@ -2,9 +2,9 @@
def test_version_fails_gracefully(mocker):
target = 'pkg_resources.get_distribution'
target = "pkg_resources.get_distribution"
mocker.patch(target, side_effect=Exception())
from pyvarint.__init__ import __version__
assert __version__ == 'unknown'
assert __version__ == "unknown"