forked from itec/banana
Changed setup + small fixes
This commit is contained in:
parent
e8cef5fcf3
commit
32d30b7b2a
4 changed files with 21 additions and 193 deletions
|
@ -72,7 +72,7 @@ def main():
|
||||||
sub = parser.add_subparsers()
|
sub = parser.add_subparsers()
|
||||||
encode = sub.add_parser("encode", help="Convert number to word")
|
encode = sub.add_parser("encode", help="Convert number to word")
|
||||||
encode.add_argument("num", type=int)
|
encode.add_argument("num", type=int)
|
||||||
encode.add_argument("--minlength", "-l", help="Set minimum length", type=int, default=6)
|
encode.add_argument("--minlength", "-l", help="Set minimum length", type=int, default=1)
|
||||||
encode.set_defaults(func=main_encode)
|
encode.set_defaults(func=main_encode)
|
||||||
|
|
||||||
decode = sub.add_parser("decode", help="Convert word to number")
|
decode = sub.add_parser("decode", help="Convert word to number")
|
||||||
|
|
|
@ -85,20 +85,5 @@ class BananaCodec(Codec):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
|
|
||||||
class RibesCodec(Codec):
|
|
||||||
def __init__(self):
|
|
||||||
super().__init__(0, 1)
|
|
||||||
|
|
||||||
|
|
||||||
class AnanasCodec(Codec):
|
|
||||||
def __init__(self):
|
|
||||||
super().__init__(1, 0)
|
|
||||||
|
|
||||||
|
|
||||||
class AvocadoCodec(Codec):
|
|
||||||
def __init__(self):
|
|
||||||
super().__init__(1, 1)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
print("Hi I'm the basebanana library")
|
print("Hi I'm the basebanana library")
|
||||||
|
|
11
setup.py
11
setup.py
|
@ -31,25 +31,24 @@ setup(
|
||||||
"Programming Language :: Python :: 3.7",
|
"Programming Language :: Python :: 3.7",
|
||||||
"Programming Language :: Python :: 3.8",
|
"Programming Language :: Python :: 3.8",
|
||||||
],
|
],
|
||||||
description="banana",
|
description="basebanana",
|
||||||
entry_points={
|
entry_points={
|
||||||
"console_scripts": [
|
"console_scripts": [
|
||||||
|
"basebanana=banana.cli:main",
|
||||||
"banana=banana.cli:main",
|
"banana=banana.cli:main",
|
||||||
"accavallavacca=banana.cli:main",
|
|
||||||
"bananarandom=banana.cli:bananarandom",
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
install_requires=requirements,
|
install_requires=requirements,
|
||||||
license="MIT license",
|
license="MIT license",
|
||||||
long_description=readme + "\n\n" + history,
|
long_description=readme + "\n\n" + history,
|
||||||
include_package_data=True,
|
include_package_data=True,
|
||||||
keywords="banana",
|
keywords="basebanana",
|
||||||
name="banana",
|
name="basebanana",
|
||||||
packages=find_packages(include=["banana", "banana.*"]),
|
packages=find_packages(include=["banana", "banana.*"]),
|
||||||
setup_requires=setup_requirements,
|
setup_requires=setup_requirements,
|
||||||
test_suite="tests",
|
test_suite="tests",
|
||||||
tests_require=test_requirements,
|
tests_require=test_requirements,
|
||||||
url="https://git.lattuga.net/itec/banana",
|
url="https://git.lattuga.net/itec/banana",
|
||||||
version="0.1.0",
|
version="0.2.0",
|
||||||
zip_safe=False,
|
zip_safe=False,
|
||||||
)
|
)
|
||||||
|
|
|
@ -5,9 +5,21 @@ import random
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from banana import AnanasCodec, AvocadoCodec, BananaCodec, RibesCodec
|
from banana import BananaCodec
|
||||||
|
|
||||||
banana_conversions = {"be": 1, "beba": 70, "zu": 69, "bezu": 139, "nana": 2485}
|
banana_conversions = {
|
||||||
|
"be": 1,
|
||||||
|
"da": 10,
|
||||||
|
"bema" : 100,
|
||||||
|
"duga": 1000,
|
||||||
|
"bibiva": 10000,
|
||||||
|
"galopa": 100000,
|
||||||
|
"bivucasa": 1000000,
|
||||||
|
"beba": 70,
|
||||||
|
"zu": 69,
|
||||||
|
"bezu": 139,
|
||||||
|
"nana": 2485,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(params=banana_conversions.items())
|
@pytest.fixture(params=banana_conversions.items())
|
||||||
|
@ -15,74 +27,9 @@ def banana_known(request):
|
||||||
yield request.param
|
yield request.param
|
||||||
|
|
||||||
|
|
||||||
avocado_conversions = {
|
|
||||||
"a": 0,
|
|
||||||
"aca": 5,
|
|
||||||
"ada": 10,
|
|
||||||
"afa": 15,
|
|
||||||
"aga": 20,
|
|
||||||
"ala": 25,
|
|
||||||
"ama": 30,
|
|
||||||
"ana": 35,
|
|
||||||
"apa": 40,
|
|
||||||
"ara": 45,
|
|
||||||
"asa": 50,
|
|
||||||
"ata": 55,
|
|
||||||
"ava": 60,
|
|
||||||
"aza": 65,
|
|
||||||
"eba": 70,
|
|
||||||
"eca": 75,
|
|
||||||
"eda": 80,
|
|
||||||
"efa": 85,
|
|
||||||
"ega": 90,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(params=avocado_conversions.items())
|
|
||||||
def avocado_known(request):
|
|
||||||
yield request.param
|
|
||||||
|
|
||||||
|
|
||||||
ribes_conversions = {"b": 0, "c": 1, "z": 13, "beb": 14, "bec": 15}
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(params=ribes_conversions.items())
|
|
||||||
def ribes_known(request):
|
|
||||||
yield request.param
|
|
||||||
|
|
||||||
|
|
||||||
ananas_conversions = {
|
|
||||||
"ac": 1,
|
|
||||||
"al": 5,
|
|
||||||
"as": 10,
|
|
||||||
"ec": 15,
|
|
||||||
"em": 20,
|
|
||||||
"et": 25,
|
|
||||||
"id": 30,
|
|
||||||
"in": 35,
|
|
||||||
"iv": 40,
|
|
||||||
"of": 45,
|
|
||||||
"op": 50,
|
|
||||||
"oz": 55,
|
|
||||||
"ug": 60,
|
|
||||||
"ur": 65,
|
|
||||||
"acab": 70,
|
|
||||||
"acal": 75,
|
|
||||||
"acas": 80,
|
|
||||||
"acec": 85,
|
|
||||||
"acem": 90,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
ananas_codec = AnanasCodec()
|
|
||||||
avocado_codec = AvocadoCodec()
|
|
||||||
banana_codec = BananaCodec()
|
banana_codec = BananaCodec()
|
||||||
ribes_codec = RibesCodec()
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(params=ananas_conversions.items())
|
|
||||||
def ananas_known(request):
|
|
||||||
yield request.param
|
|
||||||
|
|
||||||
|
|
||||||
def test_banana_to_dec_known(banana_known):
|
def test_banana_to_dec_known(banana_known):
|
||||||
|
@ -99,12 +46,6 @@ def test_banana_is_banana(banana_known):
|
||||||
assert banana_codec.is_valid(banana_known[0])
|
assert banana_codec.is_valid(banana_known[0])
|
||||||
|
|
||||||
|
|
||||||
def test_banana_is_only_banana(banana_known):
|
|
||||||
assert not ribes_codec.is_valid(banana_known[0])
|
|
||||||
assert not ananas_codec.is_valid(banana_known[0])
|
|
||||||
assert not avocado_codec.is_valid(banana_known[0])
|
|
||||||
|
|
||||||
|
|
||||||
def test_banana2dec_prefix_ba(banana_known):
|
def test_banana2dec_prefix_ba(banana_known):
|
||||||
"""un ba all'inizio non cambia nulla!"""
|
"""un ba all'inizio non cambia nulla!"""
|
||||||
word, value = banana_known
|
word, value = banana_known
|
||||||
|
@ -112,66 +53,6 @@ def test_banana2dec_prefix_ba(banana_known):
|
||||||
assert banana_codec.decode(prefix + word) == value
|
assert banana_codec.decode(prefix + word) == value
|
||||||
|
|
||||||
|
|
||||||
def test_ribes_to_dec_known(ribes_known):
|
|
||||||
word, value = ribes_known
|
|
||||||
assert ribes_codec.decode(word) == value
|
|
||||||
|
|
||||||
|
|
||||||
def test_dec_to_ribes_known(ribes_known):
|
|
||||||
word, value = ribes_known
|
|
||||||
assert ribes_codec.encode(value) == word
|
|
||||||
|
|
||||||
|
|
||||||
def test_ribes_is_ribes(ribes_known):
|
|
||||||
assert ribes_codec.is_valid(ribes_known[0])
|
|
||||||
|
|
||||||
|
|
||||||
def test_ribes_is_only_ribes(ribes_known):
|
|
||||||
assert not banana_codec.is_valid(ribes_known[0])
|
|
||||||
assert not ananas_codec.is_valid(ribes_known[0])
|
|
||||||
assert not avocado_codec.is_valid(ribes_known[0])
|
|
||||||
|
|
||||||
|
|
||||||
def test_avocado_to_dec_known(avocado_known):
|
|
||||||
word, value = avocado_known
|
|
||||||
assert avocado_codec.decode(word) == value
|
|
||||||
|
|
||||||
|
|
||||||
def test_dec_to_avocado_known(avocado_known):
|
|
||||||
word, value = avocado_known
|
|
||||||
assert avocado_codec.encode(value) == word
|
|
||||||
|
|
||||||
|
|
||||||
def test_avocado_is_avocado(avocado_known):
|
|
||||||
assert avocado_codec.is_valid(avocado_known[0])
|
|
||||||
|
|
||||||
|
|
||||||
def test_avocado_is_only_avocado(avocado_known):
|
|
||||||
assert not ribes_codec.is_valid(avocado_known[0])
|
|
||||||
assert not ananas_codec.is_valid(avocado_known[0])
|
|
||||||
assert not banana_codec.is_valid(avocado_known[0])
|
|
||||||
|
|
||||||
|
|
||||||
def test_ananas_to_dec_known(ananas_known):
|
|
||||||
word, value = ananas_known
|
|
||||||
assert ananas_codec.decode(word) == value
|
|
||||||
|
|
||||||
|
|
||||||
def test_dec_to_ananas_known(ananas_known):
|
|
||||||
word, value = ananas_known
|
|
||||||
assert ananas_codec.encode(value) == word
|
|
||||||
|
|
||||||
|
|
||||||
def test_ananas_is_ananas(ananas_known):
|
|
||||||
assert ananas_codec.is_valid(ananas_known[0])
|
|
||||||
|
|
||||||
|
|
||||||
def test_ananas_is_only_ananas(ananas_known):
|
|
||||||
assert not ribes_codec.is_valid(ananas_known[0])
|
|
||||||
assert not banana_codec.is_valid(ananas_known[0])
|
|
||||||
assert not banana_codec.is_valid(ananas_known[0])
|
|
||||||
|
|
||||||
|
|
||||||
def test_answer_to_life_the_universe_and_everything():
|
def test_answer_to_life_the_universe_and_everything():
|
||||||
banana = banana_codec.decode("banana")
|
banana = banana_codec.decode("banana")
|
||||||
assert banana != 42
|
assert banana != 42
|
||||||
|
@ -180,41 +61,4 @@ def test_answer_to_life_the_universe_and_everything():
|
||||||
|
|
||||||
def test_random_len_0():
|
def test_random_len_0():
|
||||||
assert banana_codec.random(minlength=0) == ""
|
assert banana_codec.random(minlength=0) == ""
|
||||||
assert ananas_codec.random(minlength=0) == ""
|
|
||||||
assert avocado_codec.random(minlength=0) == ""
|
|
||||||
assert ribes_codec.random(minlength=0) == ""
|
|
||||||
|
|
||||||
|
|
||||||
def test_banana_random_minlength_even():
|
|
||||||
for l in (0, 2, 4, 6, 8, 10, 12):
|
|
||||||
assert len(banana_codec.random(minlength=l)) == l
|
|
||||||
assert len(ananas_codec.random(minlength=l)) == l
|
|
||||||
|
|
||||||
|
|
||||||
def test_banana_random_minlength_odd():
|
|
||||||
for l in (1, 3, 5, 7, 9):
|
|
||||||
assert len(banana_codec.random(minlength=l)) == l + 1
|
|
||||||
assert len(ananas_codec.random(minlength=l)) == l + 1
|
|
||||||
|
|
||||||
|
|
||||||
def test_ribes_random_minlength_even():
|
|
||||||
for l in (2, 4, 6, 8, 10, 12):
|
|
||||||
assert len(ribes_codec.random(minlength=l)) == l + 1
|
|
||||||
assert len(avocado_codec.random(minlength=l)) == l + 1
|
|
||||||
|
|
||||||
|
|
||||||
def test_ribes_random_minlength_odd():
|
|
||||||
for l in (1, 3, 5, 7, 9):
|
|
||||||
assert len(ribes_codec.random(minlength=l)) == l
|
|
||||||
assert len(avocado_codec.random(minlength=l)) == l
|
|
||||||
|
|
||||||
|
|
||||||
def test_random_coherence_please():
|
|
||||||
for codec in (ribes_codec, ananas_codec, avocado_codec, banana_codec):
|
|
||||||
for seed in range(30):
|
|
||||||
word = codec.random(prng=random.Random(seed))
|
|
||||||
assert codec.is_valid(word), "%s (seed %d) non valido per %s" % (
|
|
||||||
word,
|
|
||||||
seed,
|
|
||||||
codec.__class__.__name__,
|
|
||||||
)
|
|
||||||
|
|
Loading…
Reference in a new issue