|
1 | | -#!/usr/bin/env python |
2 | | - |
3 | 1 | """Test for basplot.""" |
4 | | -import unittest |
5 | | -from glob import glob |
| 2 | + |
6 | 3 | from pathlib import Path |
| 4 | +from unittest import mock |
| 5 | + |
| 6 | +import sample_generator |
7 | 7 |
|
8 | 8 | from bashplot import bashplot |
9 | 9 |
|
| 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 | + |
10 | 122 |
|
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 |
0 commit comments