diff --git a/.gitignore b/.gitignore index 996b759..02b635b 100644 --- a/.gitignore +++ b/.gitignore @@ -58,3 +58,4 @@ history.txt .venv fake.py .vscode +*~ diff --git a/.travis.yml b/.travis.yml index d6c4ff0..5ab9f0b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,6 @@ language: python python: - 2.7 -- 3.2 -- 3.3 - 3.4 - 3.5 - 3.6 @@ -14,6 +12,7 @@ install: script: - echo -e 'x=0\nfor i in range(0, 10000000):\n x+=i\nprint(x)' > fake.py - howlong -i 1 -c python fake.py +- pytest after_success: - bash <(curl -s https://codecov.io/bash) diff --git a/HowLong/test_parser.py b/HowLong/test_parser.py index aaac078..677a175 100644 --- a/HowLong/test_parser.py +++ b/HowLong/test_parser.py @@ -1,6 +1,7 @@ -import unittest -from HowLong import HowLong +from __future__ import absolute_import +import unittest +from HowLong.HowLong import HowLong class TestParser(unittest.TestCase): @@ -13,7 +14,7 @@ def test_empty_arguments(self): '''Tests with no arguments At least one argument is required. ''' - with self.assertRaises(AssertionError): + with self.assertRaises(SystemExit): self.parser() def test_c_option_with_empty_arguments(self): @@ -29,7 +30,3 @@ def test_p_option_with_empty_arguments(self): ''' with self.assertRaises(TypeError): self.parser('-p') - - -if __name__ == "__main__": - unittest.main() diff --git a/HowLong/test_process.py b/HowLong/test_process.py new file mode 100644 index 0000000..1ca606b --- /dev/null +++ b/HowLong/test_process.py @@ -0,0 +1,29 @@ +from __future__ import absolute_import + +import os +import sys +import unittest + + +from HowLong.HowLong import Process + +class TestProcess(unittest.TestCase): + def test_command(self): + p = Process(command=["true"]) + assert p.command == "true" + assert p.start_time + + def test_pid(self): + p = Process(os.getpid()) + # Specific command could be dependent on host running test, + # settle for making sure it was filled in at all. + assert p.command + assert p.start_time + + def test_is_running_pid(self): + p = Process(os.getpid()) + assert p.is_running() + + def test_is_running_cmd(self): + p = Process(command=["true"]) + assert p.is_running() diff --git a/HowLong/test_utils.py b/HowLong/test_utils.py new file mode 100644 index 0000000..a23bca2 --- /dev/null +++ b/HowLong/test_utils.py @@ -0,0 +1,28 @@ +from __future__ import absolute_import + +import unittest +import sys + +from HowLong import HowLong + +def test_red(): + ret = HowLong.red("asdf") + assert ret == '\033[91masdf\033[0m' + + +# While it would be good to also test the printed output, +# dealing with print statement versus print function +# being different across python2 and python3 makes that +# really hard. +class TestErrorAndExit(unittest.TestCase): + def test_no_args(self): + with self.assertRaises(SystemExit): + HowLong.error_and_exit() + + def test_one_arg(self): + with self.assertRaises(SystemExit): + HowLong.error_and_exit("one") + + def test_multi_arg(self): + with self.assertRaises(SystemExit): + HowLong.error_and_exit("one", "two") diff --git a/requirements.txt b/requirements.txt index 268a7b2..19c48a6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,9 @@ psutil>=5.0.1 termcolor>=1.1.0 colorama>=0.3.9 +pytest==3.9.2 +pytest-cov==2.6.0 +six==1.11.0 +mock==2.0.0 +pbr==5.1.0 -e .