mirror of
https://github.com/LazoCoder/Pokemon-Terminal
synced 2025-02-17 05:18:31 +00:00
Merge branch 'master' into master
This commit is contained in:
commit
45d4146b2f
4 changed files with 89 additions and 4 deletions
20
.travis.yml
Normal file
20
.travis.yml
Normal file
|
@ -0,0 +1,20 @@
|
|||
sudo: false
|
||||
dist: trusty
|
||||
language: python
|
||||
python:
|
||||
- "3.5.0"
|
||||
- "3.6.1"
|
||||
- "nightly" # currently points to 3.7-dev
|
||||
install:
|
||||
- pip install flake8, pytest
|
||||
before_script:
|
||||
# stop the build if there are Python syntax errors
|
||||
- flake8 . --count --select=E901,E999 --statistics
|
||||
# exit-zero treates all errors as warnings. The GitHub editor is 127 chars wide
|
||||
- flake8 . --count --exit-zero --max-line-length=127 --statistics
|
||||
script:
|
||||
pytest --capture=sys
|
||||
# python unittest.py
|
||||
notifications:
|
||||
on_success: change
|
||||
on_failure: always
|
9
main.py
9
main.py
|
@ -2,7 +2,6 @@
|
|||
|
||||
# The main module that brings everything together.
|
||||
|
||||
from sys import argv
|
||||
from database import Database
|
||||
import random
|
||||
import scripter
|
||||
|
@ -275,7 +274,8 @@ def single_argument_handler(arg, escape_code):
|
|||
else:
|
||||
change_terminal_background(db, arg)
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
def main(argv):
|
||||
# Entrance to the program.
|
||||
if len(argv) == 1:
|
||||
print('No command line arguments specified.'
|
||||
|
@ -296,3 +296,8 @@ if __name__ == "__main__":
|
|||
else:
|
||||
print('Invalid number of arguments.'
|
||||
'\nType "help" to see all the commands.')
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Entrance to the program.
|
||||
main(sys.argv)
|
||||
|
|
56
test_main.py
Normal file
56
test_main.py
Normal file
|
@ -0,0 +1,56 @@
|
|||
#!/usr/bin/env python -m pytest --capture=sys
|
||||
|
||||
from collections import namedtuple
|
||||
from database import Database
|
||||
from main import main
|
||||
|
||||
region_record = namedtuple('region_record', 'roman_number start end')
|
||||
region_dict = {"kanto": region_record("I", 1, 151),
|
||||
"johto": region_record("II", 152, 251),
|
||||
"hoenn": region_record("III", 252, 386),
|
||||
"sinnoh": region_record("IV", 387, 493),
|
||||
"extra": region_record("", 494, 100000)}
|
||||
db = Database()
|
||||
|
||||
|
||||
def test_no_args(capsys):
|
||||
main([__file__])
|
||||
out, err = capsys.readouterr()
|
||||
assert out.startswith("No command line arguments specified.")
|
||||
|
||||
|
||||
def test_len():
|
||||
# Database unfortunately makes db.__MAX_ID private :-(
|
||||
__MAX_ID = 493
|
||||
assert len(db) == __MAX_ID + len(db.get_extra())
|
||||
|
||||
|
||||
def _test_region(region_name):
|
||||
region_name = (region_name or 'extra').lower()
|
||||
# Database unfortunately makes db.__get_region() private :-(
|
||||
func = {"kanto": db.get_kanto,
|
||||
"johto": db.get_johto,
|
||||
"hoenn": db.get_hoenn,
|
||||
"sinnoh": db.get_sinnoh,
|
||||
"extra": db.get_extra}[region_name]
|
||||
pokemon_list = func()
|
||||
region_record = region_dict[region_name]
|
||||
start = region_record.start
|
||||
end = len(db) if region_name == "extra" else region_record.end
|
||||
# make sure there are no missing pokemon
|
||||
assert len(pokemon_list) == end - start + 1
|
||||
if region_name == "extra":
|
||||
return
|
||||
# make sure that all pokemon.id are in the ID range
|
||||
assert all([start <= int(p.get_id()) <= end for p in pokemon_list])
|
||||
|
||||
|
||||
def test_regions():
|
||||
for region_name in region_dict:
|
||||
_test_region(region_name)
|
||||
|
||||
|
||||
def test_three_args(capsys):
|
||||
main([__file__, 1, 2, 3])
|
||||
out, err = capsys.readouterr()
|
||||
assert out.startswith("Invalid number of arguments.")
|
|
@ -1,7 +1,7 @@
|
|||
# This module is for testing the different components of this project.
|
||||
|
||||
from database import Database
|
||||
from sys import argv
|
||||
import sys
|
||||
|
||||
|
||||
def print_items(items):
|
||||
|
@ -71,7 +71,7 @@ def test_database_double_arg(arg):
|
|||
" exists in the Database class.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
def main(argv):
|
||||
if len(argv) == 1:
|
||||
print("No command line parameters provided.")
|
||||
elif len(argv) == 2:
|
||||
|
@ -80,3 +80,7 @@ if __name__ == "__main__":
|
|||
test_database_double_arg(argv)
|
||||
else:
|
||||
print("This module only takes one command line parameter.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(sys.argv)
|
||||
|
|
Loading…
Add table
Reference in a new issue