diff --git a/.github/workflows/python-build.yml b/.github/workflows/python-build.yml index b3be771..f5162ab 100644 --- a/.github/workflows/python-build.yml +++ b/.github/workflows/python-build.yml @@ -38,3 +38,6 @@ jobs: run: | pip install mypy pipenv run check-types + - name: End-to-End tests + run: | + pipenv run test-e2e diff --git a/Pipfile b/Pipfile index e429f4e..2df16be 100644 --- a/Pipfile +++ b/Pipfile @@ -26,4 +26,5 @@ allow_prereleases = true [scripts] lint = "flake8 . --count --max-complexity=10 --max-line-length=127 --statistics" check-types = "mypy ./license-sh" -test = "python -m unittest" +test = "python -m unittest discover -s ./tests" +test-e2e = "python -m unittest discover -s ./tests_e2e" diff --git a/tests_e2e/__init__.py b/tests_e2e/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests_e2e/test_data/__init__.py b/tests_e2e/test_data/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests_e2e/test_data/pom.xml b/tests_e2e/test_data/pom.xml new file mode 100644 index 0000000..5a068f7 --- /dev/null +++ b/tests_e2e/test_data/pom.xml @@ -0,0 +1,59 @@ + + + 4.0.0 + sh.license + 0.9.23 + license + license-sh maven test + jar + + + UTF-8 + + + + + junit + junit + 4.12 + test + + + org.javassist + javassist + 3.22.0-GA + true + + + com.fasterxml.jackson.core + jackson-annotations + 2.9.5 + true + + + com.fasterxml.jackson.core + jackson-databind + 2.9.5 + true + + + com.google.code.gson + gson + 2.8.3 + true + + + org.openjdk.jmh + jmh-core + 1.20 + test + + + org.openjdk.jmh + jmh-generator-annprocess + 1.20 + test + + + diff --git a/tests_e2e/test_maven.py b/tests_e2e/test_maven.py new file mode 100644 index 0000000..c3fbfc0 --- /dev/null +++ b/tests_e2e/test_maven.py @@ -0,0 +1,45 @@ +import unittest + +from license_sh.commands.run_license_sh import run_license_sh +from anytree.importer import JsonImporter +from unittest.mock import patch +from tests_e2e import test_data +from importlib import resources + +ARGUMENTS = { + '--config': None, + '--debug': False, + '--dependencies': False, + '--help': False, + '--interactive': False, + '--output': 'console', + '--project': None, + '--tree': False, + '--version': False, + '': None, + 'config': False +} + + +class MavenCase(unittest.TestCase): + @patch('builtins.print') + def test_valid_json(self, print_mock): + with resources.path(test_data, "") as test_data_path: + with self.assertRaises(SystemExit): + run_license_sh({**ARGUMENTS, **{ + '--output': 'json', + '': test_data_path, + '--project': 'maven' + }}) + calls = print_mock.call_args_list + + std_out = "" + for call in calls: + file_arg = call.kwargs.get('file', None) + if not file_arg: + std_out += ''.join(call.args) + self.assertTrue(bool(JsonImporter().import_(std_out))) + + +if __name__ == '__main__': + unittest.main()