Merge pull request #46 from athul/fix-tests

fix: fixes import path
This commit is contained in:
Jovial Joe Jayarson 2020-10-19 15:58:04 +05:30 committed by GitHub
commit a6b91c890b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 2 deletions

3
.gitignore vendored
View File

@ -1,2 +1,5 @@
#generated when running the tests #generated when running the tests
__pycache__/ __pycache__/
# Local VS code configurations
.vscode/

View File

@ -1,10 +1,15 @@
''' '''
Tests for the main.py Tests for the main.py
''' '''
from main import make_graph
import unittest import unittest
import os import os
try:
# For travis build which uses
# python -m unittest discover
from main import make_graph
except Exception as e:
print("Error: missing 'main.py'\nTrying ablsolute import...")
class TestMain(unittest.TestCase): class TestMain(unittest.TestCase):
@ -47,4 +52,15 @@ class TestMain(unittest.TestCase):
if __name__ == '__main__': if __name__ == '__main__':
if __package__ is None:
import sys
# because test_main.py is one level below main.py
# python test/test_main.py
sys.path.append(os.path.dirname(
os.path.dirname(os.path.abspath(__file__))))
from main import make_graph
else:
# Later on if WakaReadme is implemetaion as package
# python -m tests/test_main
from ..main import make_graph
unittest.main() unittest.main()