mirror of
https://github.com/LazoCoder/Pokemon-Terminal
synced 2024-11-23 12:23:04 +00:00
More testing
- Adds new tests of the new command engine - Regions and pokemon types and names are now case insensitive - Roll back some of the removed tests.
This commit is contained in:
parent
c9d406124a
commit
d96d4a8bb5
4 changed files with 78 additions and 10 deletions
|
@ -6,6 +6,7 @@ class Filter(Action):
|
|||
POKEMON_LIST = Database().get_all()
|
||||
filtered_list = [p for p in POKEMON_LIST]
|
||||
FILTERS = []
|
||||
EXAMPLE_VAL = None
|
||||
|
||||
def matches(self, pokemon, value):
|
||||
raise NotImplementedError
|
||||
|
@ -19,27 +20,38 @@ class Filter(Action):
|
|||
|
||||
|
||||
class NameFilter(Filter):
|
||||
def matches(self, pokemon: Pokemon, value):
|
||||
EXAMPLE_VAL = 'bulb'
|
||||
|
||||
def matches(self, pokemon: Pokemon, value: str):
|
||||
return value in pokemon.get_name()
|
||||
|
||||
|
||||
class RegionFilter(Filter):
|
||||
def matches(self, pokemon: Pokemon, value):
|
||||
EXAMPLE_VAL = 'kanto'
|
||||
|
||||
def matches(self, pokemon: Pokemon, value: str):
|
||||
return pokemon.get_region() == value
|
||||
|
||||
|
||||
class LightFilter(Filter):
|
||||
def matches(self, pokemon: Pokemon, value):
|
||||
EXAMPLE_VAL = 0.7
|
||||
|
||||
def matches(self, pokemon: Pokemon, value: float):
|
||||
return pokemon.get_dark_threshold() > value
|
||||
|
||||
|
||||
class DarkFilter(Filter):
|
||||
def matches(self, pokemon: Pokemon, value):
|
||||
EXAMPLE_VAL = 0.4
|
||||
|
||||
def matches(self, pokemon: Pokemon, value: float):
|
||||
return pokemon.get_dark_threshold() < value
|
||||
|
||||
|
||||
class TypeFilter(Filter):
|
||||
def matches(self, pokemon: Pokemon, value):
|
||||
EXAMPLE_VAL = 'water'
|
||||
|
||||
def matches(self, pokemon: Pokemon, value: str):
|
||||
value = value.lower()
|
||||
return value in (pokemon.get_pkmn_type(),
|
||||
pokemon.get_pkmn_type_secondary())
|
||||
|
||||
|
|
11
main.py
11
main.py
|
@ -63,11 +63,13 @@ def main(argv):
|
|||
'various conditions'
|
||||
)
|
||||
filtersGroup.add_argument(
|
||||
'-n', '--name', help='Filter by pokemon which '
|
||||
'name contains NAME', action=filters.NameFilter)
|
||||
'-n', '--name', help='Filter by pokemon which name contains NAME',
|
||||
action=filters.NameFilter, type=str.lower
|
||||
)
|
||||
filtersGroup.add_argument(
|
||||
'-r', '--region', help='Filter the pokemons by region',
|
||||
action=filters.RegionFilter, choices=Database.REGIONS
|
||||
action=filters.RegionFilter, choices=Database.REGIONS,
|
||||
type=str.lower
|
||||
)
|
||||
filtersGroup.add_argument(
|
||||
'-l', '--light', help='Filter out the pokemons darker then 0.xx',
|
||||
|
@ -81,7 +83,8 @@ def main(argv):
|
|||
)
|
||||
filtersGroup.add_argument(
|
||||
'-t', '--type', help='Filter the pokemons by type.',
|
||||
action=filters.TypeFilter, choices=Database.POKEMON_TYPES
|
||||
action=filters.TypeFilter, choices=Database.POKEMON_TYPES,
|
||||
type=str.lower
|
||||
)
|
||||
filtersGroup.add_argument(
|
||||
'-ne', '--no-extras', help='Excludes extra pokemons',
|
||||
|
|
29
test_filters.py
Normal file
29
test_filters.py
Normal file
|
@ -0,0 +1,29 @@
|
|||
from filters import Filter
|
||||
import pytest
|
||||
|
||||
|
||||
def test_basic_loading():
|
||||
assert len(Filter.POKEMON_LIST) >= 493
|
||||
assert len(Filter.filtered_list) == len(Filter.POKEMON_LIST)
|
||||
|
||||
|
||||
def test_filters_infrastructure():
|
||||
inst = Filter(None, None)
|
||||
with pytest.raises(NotImplementedError):
|
||||
inst.matches(None, None)
|
||||
for fltr in Filter.FILTERS:
|
||||
fltr = fltr(None, None)
|
||||
filtered = [pkmn for pkmn in Filter.POKEMON_LIST
|
||||
if fltr.matches(pkmn, fltr.EXAMPLE_VAL)]
|
||||
assert len(filtered) < len(Filter.POKEMON_LIST)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# Test runner: Runs all functions whose name begins with `test_`
|
||||
# locals() changes when trying to do this without the list comprehension!!!
|
||||
name_funcs = [(n, f) for n, f in locals().items() if n.startswith('test_')]
|
||||
for name, func in name_funcs:
|
||||
if callable(func):
|
||||
func()
|
||||
else:
|
||||
print(name + ' is not callable()!')
|
26
test_main.py
26
test_main.py
|
@ -10,7 +10,31 @@ from test_utils import region_dict
|
|||
import random
|
||||
|
||||
db = Database()
|
||||
print(len(db))
|
||||
|
||||
|
||||
def broken_test_no_args(capsys):
|
||||
""" FIXME: Now the the main file accepts zero arguments """
|
||||
main([__file__])
|
||||
out, err = capsys.readouterr()
|
||||
assert out.startswith("No command line arguments specified.")
|
||||
|
||||
|
||||
def broken_test_three_args(capsys):
|
||||
""" FIXME: Now the main file accepts way more then 3 arguments """
|
||||
main([__file__, 1, 2, 3])
|
||||
out, err = capsys.readouterr()
|
||||
assert out.startswith("Invalid number of arguments.")
|
||||
|
||||
|
||||
def broken_test_two_letters(capsys):
|
||||
""" FIXME: The search argorhytm is now bultin the name filter """
|
||||
main([__file__, 'bu'])
|
||||
out, err = capsys.readouterr()
|
||||
assert 'Butterfree' in out
|
||||
# prefix search only
|
||||
main([__file__, 'ut'])
|
||||
out, err = capsys.readouterr()
|
||||
assert 'butterfree' not in out.lower()
|
||||
|
||||
|
||||
def test_extra(capsys):
|
||||
|
|
Loading…
Reference in a new issue