Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make tests runnable with pytest. #39

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,4 @@ history.txt
.venv
fake.py
.vscode
*~
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
language: python
python:
- 2.7
- 3.2
- 3.3
- 3.4
- 3.5
- 3.6
Expand All @@ -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)
11 changes: 4 additions & 7 deletions HowLong/test_parser.py
Original file line number Diff line number Diff line change
@@ -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):

Expand All @@ -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):
Expand All @@ -29,7 +30,3 @@ def test_p_option_with_empty_arguments(self):
'''
with self.assertRaises(TypeError):
self.parser('-p')


if __name__ == "__main__":
unittest.main()
29 changes: 29 additions & 0 deletions HowLong/test_process.py
Original file line number Diff line number Diff line change
@@ -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()
28 changes: 28 additions & 0 deletions HowLong/test_utils.py
Original file line number Diff line number Diff line change
@@ -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")
5 changes: 5 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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 .