Skip to content

Commit

Permalink
Add test to make sure aircraft database works
Browse files Browse the repository at this point in the history
  • Loading branch information
aarondettmann committed Mar 6, 2020
1 parent 1275327 commit 770c54f
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 4 deletions.
1 change: 0 additions & 1 deletion docs/TODO.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# TODO

## JSON aircraft database
* Add tests (make sure all aircraft can be run)
* Add "comment": "xyz" in JSON file and use as description for `print_available_aircraft()`
* Find/add more relevant example aircraft

Expand Down
2 changes: 1 addition & 1 deletion run_pytest.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env bash

pytest -v --cov=pytornado --cov-report=html tests/
pytest -vs --cov=pytornado --cov-report=html tests/
2 changes: 1 addition & 1 deletion src/bin/_pytornado_exe.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from commonlibs.logger.logger import truncate_filepath

from pytornado.__version__ import __version__
import pytornado.database.aircraft.tools as dbtools
import pytornado.database.tools as dbtools
import pytornado.stdfun.run as stdrun
import pytornado.stdfun.setup as project_setup

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@

logger = logging.getLogger(__name__)

PATH_AIRCRAFT_DB = 'aircraft'


def get_aircraft_db_path():
"""
Expand All @@ -42,7 +44,10 @@ def get_aircraft_db_path():
:path_aircraft_db: (str) absolute path
"""

path_aircraft_db = os.path.abspath(os.path.dirname(__file__))
path_aircraft_db = os.path.join(
os.path.abspath(os.path.dirname(__file__)),
PATH_AIRCRAFT_DB
)
return path_aircraft_db


Expand Down
41 changes: 41 additions & 0 deletions tests/integration/cli/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import shutil
from pathlib import Path

import pytornado.database.tools as dbtools

def which(program):
"""
Expand Down Expand Up @@ -80,3 +81,43 @@ def test_basic_usage():
assert results_dir.is_dir() is False

shutil.rmtree(project_dir, ignore_errors=True)


def test_database():
"""
Test that all aircraft in the database can be loaded and run
"""

# Paths
project_dir = Path('pytornado')
shutil.rmtree(project_dir, ignore_errors=True)

# ------ Iterate through all aircraft in database -----
for aircraft in dbtools.list_aircraft_names():
print(f"Testing aircraft '{aircraft}'")
os.system(f"pytornado -v --mdb {aircraft}")
assert project_dir.is_dir()

settings_file = Path(os.path.join(project_dir, 'settings', f'{aircraft}.json'))
results_dir = Path(os.path.join(project_dir, '_results'))
plot_dir = Path(os.path.join(project_dir, '_plots'))

# ------ Make sure it runs -----
with open(settings_file, "r") as fp:
settings = json.load(fp)
settings['plot']['results']['show'] = False
settings['plot']['results']['save'] = True
with open(settings_file, "w") as fp:
json.dump(settings, fp)
os.system(f"pytornado -v --clean --run {settings_file}")
os.system(f"pytornado -v --run {settings_file}")
assert plot_dir.is_dir()
assert results_dir.is_dir()

# ------ Test the cleaning -----
os.system(f"pytornado --clean-only --run {settings_file}")
assert settings_file.is_file() is True
assert plot_dir.is_dir() is False
assert results_dir.is_dir() is False

shutil.rmtree(project_dir, ignore_errors=True)

0 comments on commit 770c54f

Please sign in to comment.