コード例 #1
0
def test_ids():
    db = Database()
    numbered_ids = [p.get_id() for p in db.get_all() if p.get_id() != '---']
    # test that all that are not --- are unique (no duplicate ids)
    assert len(set(numbered_ids)) == len(numbered_ids) == MAX_ID
    for id_str in numbered_ids:
        assert len(id_str) == 3
        assert isinstance(id_str, str)
        assert 1 <= int(id_str) <= MAX_ID
コード例 #2
0
def party_get_pokemon():
    file = open(party_file, 'r')
    lines = file.read().splitlines()
    db = Database()
    pokemon = []
    for line in lines:
        if db.pokemon_name_exists(line):
            pokemon.append(line)
    file.close()
    return pokemon
コード例 #3
0
def multiple_argument_handler(arg, arg2, escape_code):
    db = Database()
    rand = arg.startswith("rnd")
    if "slideshow" in arg:
        try:
            if arg.endswith("slideshow"):
                slideshow(db, 1, 494, arg2, rand)
            elif arg.endswith("slideshow-kanto"):
                slideshow(db, 1, 152, arg2, rand)
            elif arg.endswith("slideshow-johto"):
                slideshow(db, 152, 252, arg2, rand)
            elif arg.endswith("slideshow-hoenn"):
                slideshow(db, 252, 387, arg2, rand)
            elif arg.endswith("slideshow-sinnoh"):
                slideshow(db, 387, 494, arg2, rand)
            elif arg.endswith("slideshow-unova"):
                slideshow(db, 494, 650, arg2, rand)
            elif arg.endswith("slideshow-kalos"):
                slideshow(db, 650, 720, arg2, rand)
            else:
                print('Invalid slideshow command specified.'
                      '\nType "help" to see all the commands.')
        except ValueError:
            print('The slideshow time needs to be a positive number'
                  '\nType "help" to see all the commands.')
    elif arg.lower() == 'type':
        arg2 = arg2.lower()
        if arg2 not in db.get_pokemon_types():
            print("Invalid type specified")
        else:
            target = db.get_pokemon_of_type(arg2).get_name()
            if escape_code:
                change_wallpaper(db, target)
            else:
                change_terminal_background(db, target)
    elif "party-show" in arg:
        try:
            party.party_show(db, arg2, rand)
        except ValueError:
            print('The slideshow time needs to be a positive number'
                  '\nType "help" to see all the commands.')
    elif arg.lower() == 'party-add':
        arg2 = arg2.lower()
        party.party_add(arg2)
    elif arg.lower() == 'party-remove':
        arg2 = arg2.lower()
        party.party_remove(arg2) 
    else:
        print('Invalid command specified.'
              '\nType "help" to see all the commands.')
コード例 #4
0
def region_test(region_name):
    db = Database()
    # test db.get_region()
    pokemon = get_region(db, region_name)
    assert pokemon, 'No pokemon found in region: ' + region_name
    # test that region_name is in region_dict
    region_info = region_dict[region_name]
    delta = region_info.end - region_info.start
    fmt = 'Testing {}({} vs. {}): {}'
    print(fmt.format(region_name, len(pokemon), delta + 1, region_info))
    # test db.get_pokemon(id)
    middle_pokemon = db.get_pokemon(region_info.start + (delta // 2))
    assert middle_pokemon in pokemon
    # test db.get_pokemon(name)
    name = middle_pokemon.get_name()
    assert db.get_pokemon(name) in pokemon
コード例 #5
0
def region_length_test(region_name):
    db = Database()
    # test db.get_region()
    pokemon = get_region(db, region_name)
    assert pokemon, 'No pokemon found in region: ' + region_name
    # test that region_name is in region_dict
    region_info = region_dict[region_name]
    # extra_count = extra_counts.get(region_name, 0)
    expected_len = region_info.end - region_info.start + 1  # + extra_count
    fmt = 'Testing {}({} vs. {}): {}'
    print(fmt.format(region_name, len(pokemon), expected_len, region_info))
    # test the number of pokemon returned by db.get_region()
    assert len(pokemon) == expected_len
コード例 #6
0
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

    def __init_subclass__(cls, **kwargs):
        Filter.FILTERS.append(cls)

    def __call__(self, parser, namespace, value, option_string=None):
        Filter.filtered_list = [
            pkmn for pkmn in Filter.filtered_list if self.matches(pkmn, value)
        ]
コード例 #7
0
def _test_region(region_name):
    db = Database()
    # Database unfortunately makes db.__get_region() private :-(
    func = {
        "kanto": db.get_kanto,
        "johto": db.get_johto,
        "hoenn": db.get_hoenn,
        "sinnoh": db.get_sinnoh,
        "unova": db.get_unova,
        "kalos": db.get_kalos
    }[region_name]
    pokemon_list = func()
    region_record = region_dict[region_name]
    # make sure there are no missing pokemon
    start = region_record.start
    end = region_record.end
    # extra_count = extra_counts.get(region_name, 0)
    assert len(pokemon_list) == end - start + 1  # + extra_count
    # make sure that all pokemon.id == '---' or are in the ID range
    assert all([start <= int(p.get_id()) <= end for p in pokemon_list if p.get_id() != '---'])
コード例 #8
0
def test_hoenn_length(region_name='hoenn'):
    assert len(Database().get_hoenn()) == expected_len(region_name)
コード例 #9
0
def test_johto_length(region_name='johto'):
    assert len(Database().get_johto()) == expected_len(region_name)
コード例 #10
0
def test_second_database():
    print('{} items in second database.'.format(len(Database())))
コード例 #11
0
def test_lists():
    db = Database()
    load_list = load_all_pokemon()
    for db_p, load_p in zip(db.get_all(), load_list):
        assert str(db_p) == str(load_p)
        compare_pokemon(db_p, load_p)
コード例 #12
0
def test_len():
    assert len(Database()) == len(load_all_pokemon()) \
        == MAX_ID + expected_len('extra')
コード例 #13
0
def test_thresholds():
    db = Database()
    assert all(isinstance(p.get_dark_threshold(), float) for p in db.get_all())
コード例 #14
0
def test_extra_length(region_name='extra'):
    assert len(Database().get_extra()) == expected_len(region_name)
コード例 #15
0
def test_kalos_length(region_name='kalos'):
    assert len(Database().get_kalos()) == expected_len(region_name)
コード例 #16
0
def test_get_extras():
    db = Database()
    assert db.get_extra(), 'db.get_extra() returns no pokemon'
    assert len(db.get_extra()) == sum(make_extra_counts().values())
コード例 #17
0
def test_extra_counts():
    assert len(Database()) == MAX_ID + sum(make_extra_counts().values())
コード例 #18
0
def test_len():
    db = Database()
    assert len(db) == MAX_ID + len(db.get_extra())
    assert len(db.get_all()) == MAX_ID + len(db.get_extra())
コード例 #19
0
def test_sinnoh_length(region_name='sinnoh'):
    assert len(Database().get_sinnoh()) == expected_len(region_name)
コード例 #20
0
def test_unova_length(region_name='unova'):
    assert len(Database().get_unova()) == expected_len(region_name)
コード例 #21
0
def test_database_double_arg(arg):
    # Test the database where there are two command line parameters.
    # The first parameter is the name of the method to test.
    # The second parameter is the input parameter for the method that is being test.
    arg1 = arg[1].lower()
    arg2 = arg[2].lower()
    db = Database()
    if arg1 == "__contains__":
        print(arg2 in db)
    elif arg1 == "pokemon_id_exists":
        print(db.pokemon_id_exists(arg2))
    elif arg1 == "pokemon_name_exists":
        print(db.pokemon_name_exists(arg2))
    elif arg1 == "get_pokemon":
        print(db.get_pokemon(arg2))
    elif arg1 == "get_pokemon_by_name":
        print(db.get_pokemon_by_name(arg2))
    elif arg1 == "get_pokemon_by_id":
        print(db.get_pokemon_by_id(arg2))
    elif arg1 == "names_with_prefix":
        print_items(db.names_with_prefix(arg2))
    elif arg1 == "names_with_infix":
        print_items(db.names_with_infix(arg2))
    elif arg1 == "get_light":
        print_items(db.get_light(threshold=int(arg2) / 10, all_pkmn=True))
    elif arg1 == "get_dark":
        print_items(db.get_dark(threshold=int(arg2) / 10, all_pkmn=True))
    else:
        print("No such public method '" + arg + "' with two parameters"
              " exists in the Database class.")
コード例 #22
0
def test_all_length(region_name='all'):
    expected = expected_len(region_name) + expected_len('extra')
    assert len(Database().get_all()) == expected
コード例 #23
0
def test_first_database():
    print('{} items in first database.'.format(len(Database())))
コード例 #24
0
def test_database_single_arg(arg):
    # Test the database where there is a single command line parameter.
    # The parameter is the name of the method to test.
    arg = arg[1].lower()
    db = Database()
    if arg == "__str__":
        print(db)
    elif arg == "__len__":
        print(len(db))
    elif arg == "get_all":
        print_items(db.get_all())
    elif arg == "get_regions":
        print_items(db.get_regions())
    elif arg == "get_kanto":
        print_items(db.get_kanto())
    elif arg == "get_johto":
        print_items(db.get_johto())
    elif arg == "get_hoenn":
        print_items(db.get_hoenn())
    elif arg == "get_sinnoh":
        print_items(db.get_sinnoh())
    elif arg == "get_unova":
        print_items(db.get_unova())
    elif arg == "get_kalos":
        print_items(db.get_kalos())
    elif arg == "get_extra":
        print_items(db.get_extra())
    elif arg == "get_random":
        print(db.get_random())
    else:
        print("No such public method '" + arg +
              "' with zero parameters exists in the Database class.")
コード例 #25
0
def single_argument_handler(arg, escape_code):
    """Handle the logic for when there is only one command line parameter inputted."""
    db = Database()

    if len(arg) < 3 and arg.isalpha():
        prefix_search(db, arg)
    elif arg == "extra":
        print_extra(db)
    elif arg == "regions":
        print_list(db.get_regions())
    elif arg == "help" or arg.startswith("-h"):
        print_usage()
    elif arg == "kanto":
        print_columns(db.get_kanto())
    elif arg == "johto":
        print_columns(db.get_johto())
    elif arg == "hoenn":
        print_columns(db.get_hoenn())
    elif arg == "sinnoh":
        print_columns(db.get_sinnoh())
    elif arg == "unova":
        print_columns(db.get_unova())
    elif arg == "kalos":
        print_columns(db.get_kalos())
    elif arg == "all":
        print_columns(db.get_all())
    elif arg in ("clear", "disable", "off"):
        scripter.clear_terminal()
    elif arg == "random" and escape_code:
        change_wallpaper(db, db.get_random())
    elif arg == "random-kanto" and escape_code:
        change_wallpaper(db, db.get_random_from_region("kanto"))
    elif arg == "random-johto" and escape_code:
        change_wallpaper(db, db.get_random_from_region("johto"))
    elif arg == "random-hoenn" and escape_code:
        change_wallpaper(db, db.get_random_from_region("hoenn"))
    elif arg == "random-sinnoh" and escape_code:
        change_wallpaper(db, db.get_random_from_region("sinnoh"))
    elif arg == "random-unova" and escape_code:
        change_wallpaper(db, db.get_random_from_region("unova"))
    elif arg == "random-kalos" and escape_code:
        change_wallpaper(db, db.get_random_from_region("kalos"))
    elif arg == "random":
        change_terminal_background(db, db.get_random())
    elif arg == "random-kanto":
        change_terminal_background(db, db.get_random_from_region("kanto"))
    elif arg == "random-johto":
        change_terminal_background(db, db.get_random_from_region("johto"))
    elif arg == "random-hoenn":
        change_terminal_background(db, db.get_random_from_region("hoenn"))
    elif arg == "random-sinnoh":
        change_terminal_background(db, db.get_random_from_region("sinnoh"))
    elif arg == "random-unova":
        change_terminal_background(db, db.get_random_from_region("unova"))
    elif arg == "random-kalos":
        change_terminal_background(db, db.get_random_from_region("kalos"))
    elif arg == "light" and escape_code:
        change_wallpaper(db, db.get_light())
    elif arg == "dark" and escape_code:
        change_wallpaper(db, db.get_dark())
    elif arg == "light":
        change_terminal_background(db, db.get_light())
    elif arg == "dark":
        change_terminal_background(db, db.get_dark())
    elif arg in ("type", "types"):
        print_types(db.get_pokemon_types())
    elif arg == "slideshow":
        slideshow(db, 1, 494)
    elif arg == "slideshow-kanto":
        slideshow(db, 1, 152)
    elif arg == "slideshow-johto":
        slideshow(db, 152, 252)
    elif arg == "slideshow-hoenn":
        slideshow(db, 252, 387)
    elif arg == "slideshow-sinnoh":
        slideshow(db, 387, 494)
    elif arg == "slideshow-unova":
        slideshow(db, 494, 650)
    elif arg == "slideshow-kalos":
        slideshow(db, 650, 720)
    elif arg.endswith("slideshow"):
        slideshow(db, 1, 494, rand=arg.startswith("rnd"))
    elif arg.endswith("slideshow-kanto"):
        slideshow(db, 1, 152, rand=arg.startswith("rnd"))
    elif arg.endswith("slideshow-johto"):
        slideshow(db, 152, 252, rand=arg.startswith("rnd"))
    elif arg.endswith("slideshow-hoenn"):
        slideshow(db, 252, 387, rand=arg.startswith("rnd"))
    elif arg.endswith("slideshow-sinnoh"):
        slideshow(db, 387, 494, rand=arg.startswith("rnd"))
    elif arg.endswith("slideshow-unova"):
        slideshow(db, 494, 650, rand=arg.startswith("rnd"))
    elif arg.endswith("slideshow-kalos"):
        slideshow(db, 650, 720, rand=arg.startswith("rnd"))
    elif arg == "?":
        print("This function is deprecated.")
    elif arg == "evolve":
        evolve(db)
    elif arg == "party":
        party.party_print()
    elif arg == "party-show":
        party.party_show(db)
    elif arg.endswith("party-show"):
        party.party_show(db, rand=arg.startswith("rnd"))
    elif escape_code:
        change_wallpaper(db, arg)
    else:
        change_terminal_background(db, arg)
コード例 #26
0
#!/usr/bin/env python3

# To run the tests, use: python3 -m pytest --capture=sys

from pokemonterminal.database import Database
from pokemonterminal.main import main
from tests.test_utils import region_dict

db = Database()
print(len(db))


def test_no_args(capsys):
    main([__file__])
    out, err = capsys.readouterr()
    assert out.startswith("No command line arguments specified.")


def test_three_args(capsys):
    main([__file__, 1, 2, 3])
    out, err = capsys.readouterr()
    assert out.startswith("Invalid number of arguments.")


def test_two_letters(capsys):
    main([__file__, 'bu'])
    out, err = capsys.readouterr()
    assert 'Butterfree' in out
    # prefix search only
    main([__file__, 'ut'])
    out, err = capsys.readouterr()
コード例 #27
0
def broken_test_kanto_length(region_name='kanto'):
    assert len(Database().get_kanto()) == expected_len(region_name)