Skip to content

Commit d8a747b

Browse files
authored
Merge pull request #18 from Anselmoo/pytest
Change from unitest to pytest
2 parents 31d1022 + 12779e8 commit d8a747b

14 files changed

+148
-378
lines changed

.github/workflows/python-package.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,14 @@ jobs:
3535
isort . --check -v
3636
flake8 . --count --exit-zero --max-complexity=10 --statistics
3737
pydocstyle --convention=numpy -e bashplot/bashplot.py
38-
- name: Test with pytest
38+
- name: Install bashplot
3939
run: |
40-
coverage run --source=./test -m unittest
40+
pip install .
41+
- name: Test with pytest and coverage
42+
run: |
43+
coverage run -m pytest test/test*.py -vv
4144
coverage report -m
45+
coverage xml
4246
- name: Codecov
4347
uses: codecov/codecov-action@v1
4448
with:

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
include Pipfile
2-
include Pipfile.lock
32
include requirements.txt
3+
include dev-requirements.txt
44
include LICENSE
55
include MANIFEST.in
66
include README.md

Pipfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ bashplot = {editable = true, path = "."}
88

99
[dev-packages]
1010
coverage = "*"
11-
pytest = "*"
1211
isort = "*"
1312
black = "==20.8b1"
1413
flake8 = "*"
1514
pydocstyle = "*"
15+
pytest = "*"
16+
pytest-clarity = "*"
17+
pytest-cov = "*"
18+
pytest-sugar = "*"
1619

1720
[requires]
1821
python_version = "3.8"

azure-pipelines.yml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,23 @@ steps:
2828
- script: |
2929
python -m pip install --upgrade pip
3030
pip install -r requirements.txt
31-
pip install black
32-
pip install flake8
33-
pip install pydocstyle
34-
flake8 bashplot/ --count --max-line-length=88 --ignore=W293,W291 --statistic
35-
black bashplot/ --check -v
36-
pydocstyle bashplot/bashplot.py
31+
pip install -r dev-requirements.txt
3732
displayName: 'Install dependencies'
3833

34+
- script: |
35+
flake8 bashplot/ --count --max-line-length=88 --ignore=W293,W291 --statistic
36+
black . --check -v
37+
isort . --check -v
38+
flake8 . --count --exit-zero --max-complexity=10 --statistics
39+
pydocstyle --convention=numpy -e bashplot/bashplot.py
40+
displayName: 'Check style and settings'
41+
3942
- script: |
4043
python setup.py install
4144
displayName: 'Install bashplot'
4245

4346
- script: |
44-
45-
pip install coverage
46-
pip install pytest-azurepipelines
47-
cd test
48-
coverage run -m unittest test_bashplot.py
49-
coverage report
47+
coverage run -m pytest test/test*.py -vv
48+
coverage report -m
49+
coverage xml
5050
displayName: 'pytest'

bashplot/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
"""bashplot."""
2-
__version__ = "0.25"
2+
__version__ = "0.3"

bashplot/bashplot.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,7 @@
1717
import numpy as np
1818
import plotille as plt
1919

20-
try:
21-
from . import __version__
22-
except ImportError:
23-
from __init__ import __version__
24-
25-
if sys.version < "3":
26-
print("Unsupported Python Version (version < 3)!")
27-
sys.exit(1)
20+
from . import __version__
2821

2922

3023
def log(msg, mode=None):

dev-requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ pydocstyle==5.1.1
2525
pyflakes==2.2.0; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
2626
pyparsing==2.4.7; python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'
2727
pytest==6.2.1
28+
pytest-clarity==0.3.0a0
29+
pytest-sugar==0.9.4
2830
regex==2020.11.13
2931
snowballstemmer==2.0.0
3032
toml==0.10.2; python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'

test/sample_generator.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,4 @@ def generate(fname="test_data"):
4545
x = np.linspace(-0.3, 0.3)
4646
y = np.random.normal(mu, sigma, 50)
4747
data = np.array([x, y]).T
48-
np.savetxt(Path(f"./{fname}__random_gaussian.txt"), data)
49-
50-
51-
if __name__ == "__main__":
52-
generate()
48+
np.savetxt(Path(f"./{fname}_random_gaussian.txt"), data)

test/test_bashplot.py

Lines changed: 120 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,126 @@
1-
#!/usr/bin/env python
2-
31
"""Test for basplot."""
4-
import unittest
5-
from glob import glob
2+
63
from pathlib import Path
4+
from unittest import mock
5+
6+
import sample_generator
77

88
from bashplot import bashplot
99

10+
sample_generator.generate()
11+
12+
print()
13+
14+
test_txt = Path.cwd().glob("test*.txt")
15+
test_dat = Path.cwd().glob("test*.dat")
16+
17+
args_1 = {
18+
"infile": test_txt,
19+
"comments": None,
20+
"delimiter": None,
21+
"skip_header": 0,
22+
"skip_footer": 0,
23+
"usecols": (0, 1),
24+
"size": [30, 20],
25+
"x_limits": None,
26+
"y_limits": None,
27+
"scatter": False,
28+
"color": False,
29+
"legend": True,
30+
"version": False,
31+
}
32+
args_2 = {
33+
"infile": test_txt,
34+
"comments": None,
35+
"delimiter": None,
36+
"skip_header": 2,
37+
"skip_footer": 2,
38+
"usecols": (0, 1),
39+
"size": [60, 40],
40+
"x_limits": [0.0, 3.0],
41+
"y_limits": [0.0, 3.0],
42+
"scatter": True,
43+
"color": True,
44+
"legend": False,
45+
"version": True,
46+
}
47+
# Example with different delimiter
48+
args_3 = {
49+
"infile": test_dat,
50+
"comments": None,
51+
"delimiter": "\t",
52+
"skip_header": 2,
53+
"skip_footer": 2,
54+
"usecols": (0, 1, 2, 3),
55+
"size": [40, 30],
56+
"x_limits": [0.0, 3.0],
57+
"y_limits": [0.0, 3.0],
58+
"scatter": False,
59+
"color": True,
60+
"legend": True,
61+
"version": True,
62+
}
63+
64+
65+
def test_fnames():
66+
assert bashplot.get_args(opt={"infile": test_txt})["infile"] == test_txt
67+
68+
69+
def test_options_scatter():
70+
assert bashplot.get_args(opt={"scatter": True})["scatter"] is True
71+
72+
73+
def test_options_color():
74+
assert bashplot.get_args(opt={"color": True})["color"] is True
75+
76+
77+
def test_options_legend():
78+
assert bashplot.get_args(opt={"legend": False})["legend"] is False
79+
80+
81+
def test_options_version():
82+
assert bashplot.get_args(opt={"version": True})["version"] is True
83+
84+
85+
def test_xlimits():
86+
assert bashplot.get_args(opt={"x_limits": [0.0, 20.0]})["x_limits"] == [0.0, 20.0]
87+
88+
89+
def test_ylimits():
90+
assert bashplot.get_args(opt={"y_limits": [0.0, 20.0]})["y_limits"] == [0.0, 20.0]
91+
92+
93+
def test_size():
94+
assert bashplot.get_args(opt={"size": [60, 60]})["size"] == [60, 60]
95+
96+
97+
def test_ranges_default():
98+
assert bashplot.get_args()["size"] == [60, 40]
99+
100+
101+
def test_usecols():
102+
assert bashplot.get_args(opt={"usecols": [0, 2, 5]})["usecols"] == [0, 2, 5]
103+
104+
105+
@mock.patch("bashplot.bashplot.bashplot")
106+
def test_default_run(bashplot):
107+
bashplot.bashplot(fnames=test_txt, args=args_1)
108+
assert bashplot.bashplot.is_called
109+
110+
111+
@mock.patch("bashplot.bashplot.bashplot")
112+
def test_customize_run_1(bashplot):
113+
bashplot.bashplot(fnames=test_txt, args=args_2)
114+
assert bashplot.bashplot.is_called
115+
116+
117+
@mock.patch("bashplot.bashplot.bashplot")
118+
def test_customize_run_2(bashplot):
119+
bashplot.bashplot(fnames=test_dat, args=args_3)
120+
assert bashplot.bashplot.is_called
121+
10122

11-
class BashplotTestCase(unittest.TestCase):
12-
def call_bashplot(self, args):
13-
args = bashplot.get_args()
14-
return bashplot.bashplot(args)
15-
16-
def setUp(self):
17-
self.infile = glob("test*.txt")
18-
self.args_1 = {
19-
"infile": self.infile,
20-
"comments": None,
21-
"delimiter": None,
22-
"skip_header": 0,
23-
"skip_footer": 0,
24-
"usecols": (0, 1),
25-
"size": [30, 20],
26-
"x_limits": None,
27-
"y_limits": None,
28-
"scatter": False,
29-
"color": False,
30-
"legend": True,
31-
"version": False,
32-
}
33-
self.args_2 = {
34-
"infile": self.infile,
35-
"comments": None,
36-
"delimiter": None,
37-
"skip_header": 2,
38-
"skip_footer": 2,
39-
"usecols": (0, 1),
40-
"size": [60, 40],
41-
"x_limits": [0.0, 3.0],
42-
"y_limits": [0.0, 3.0],
43-
"scatter": True,
44-
"color": True,
45-
"legend": False,
46-
"version": True,
47-
}
48-
# Example with different delimiter
49-
self.singlefile = [Path("./test_data_mixed.dat")]
50-
self.args_3 = {
51-
"infile": self.singlefile,
52-
"comments": None,
53-
"delimiter": "\t",
54-
"skip_header": 2,
55-
"skip_footer": 2,
56-
"usecols": (0, 1, 2, 3),
57-
"size": [40, 30],
58-
"x_limits": [0.0, 3.0],
59-
"y_limits": [0.0, 3.0],
60-
"scatter": False,
61-
"color": True,
62-
"legend": True,
63-
"version": True,
64-
}
65-
66-
def test_fnames(self):
67-
self.assertEqual(
68-
bashplot.get_args(opt={"infile": self.infile})["infile"], self.infile
69-
)
70-
71-
def test_options(self):
72-
self.assertTrue(bashplot.get_args(opt={"scatter": True})["scatter"])
73-
self.assertTrue(bashplot.get_args(opt={"color": True})["color"])
74-
self.assertFalse(bashplot.get_args(opt={"legend": False})["legend"])
75-
self.assertTrue(bashplot.get_args(opt={"version": True})["version"])
76-
77-
def test_ranges(self):
78-
self.assertEqual(
79-
bashplot.get_args(opt={"x_limits": [0.0, 20.0]})["x_limits"], [0.0, 20.0]
80-
)
81-
self.assertEqual(
82-
bashplot.get_args(opt={"y_limits": [0.0, 20.0]})["y_limits"], [0.0, 20.0]
83-
)
84-
self.assertEqual(bashplot.get_args(opt={"size": [60, 60]})["size"], [60, 60])
85-
self.assertEqual(bashplot.get_args()["size"], [60, 40])
86-
self.assertEqual(
87-
bashplot.get_args(opt={"usecols": [0, 2, 5]})["usecols"], [0, 2, 5]
88-
)
89-
90-
def test_default_run(self):
91-
bashplot.bashplot(fnames=self.infile, args=self.args_1)
92-
assert 1
93-
94-
def test_customize_run_1(self):
95-
bashplot.bashplot(fnames=self.infile, args=self.args_2)
96-
assert 1
97-
98-
def test_customize_run_2(self):
99-
bashplot.bashplot(fnames=self.singlefile, args=self.args_3)
100-
assert 1
101-
102-
103-
if __name__ == "__main__":
104-
unittest.main()
123+
@mock.patch("bashplot.bashplot.command_line_runner")
124+
def test_command_line(command_line_runner):
125+
bashplot.command_line_runner()
126+
assert bashplot.command_line_runner.is_called

test/test_data_cos.txt

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)