From 2c28e537b6300b173826e8d1a34b9a803ab2f71a Mon Sep 17 00:00:00 2001 From: Maeva Pourpoint <maeva@passcal.nmt.edu> Date: Wed, 9 Sep 2020 15:32:15 -0600 Subject: [PATCH] Add unit tests to ensure code basic functionalities --- .gitlab-ci.yml | 1 + tests/test_mseedpeek.py | 21 +++++++++------------ tox.ini | 1 + 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7e7082b..ed0077b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -27,6 +27,7 @@ linting: stage: test script: - flake8 --ignore=F403,F405,F821,F841,W504 mseedpeek + - flake8 tests python3.6: image: python:3.6 diff --git a/tests/test_mseedpeek.py b/tests/test_mseedpeek.py index df486fd..5d25a98 100644 --- a/tests/test_mseedpeek.py +++ b/tests/test_mseedpeek.py @@ -4,21 +4,18 @@ """Tests for `mseedpeek` package.""" import unittest -import sys -try: - import mseedpeek -except ImportError: - pass +from unittest.mock import patch +from mseedpeek.mseedpeek import main + class TestMseedpeek(unittest.TestCase): """Tests for `mseedpeek` package.""" - def setUp(self): - """Set up test fixtures, if any.""" - - def tearDown(self): - """Tear down test fixtures, if any.""" - def test_import(self): - self.assertTrue('mseedpeek' in sys.modules, "Mseedpeek import failed!") + """Test mseedpeek import""" + with patch('sys.argv', ['mseedpeek', '-#']): + with self.assertRaises(SystemExit) as cmd: + main() + self.assertEqual(cmd.exception.code, 0, "sys.exit(0) never called " + "- Failed to exercise mseedpeek") diff --git a/tox.ini b/tox.ini index 86082c8..980627c 100644 --- a/tox.ini +++ b/tox.ini @@ -5,6 +5,7 @@ envlist = py36, py37, py38, flake8 basepython = python deps = flake8 commands = flake8 --ignore=F403,F405,F821,F841,W504 mseedpeek + flake8 tests [testenv] commands = python -m unittest -- GitLab