OLD | NEW |
| (Empty) |
1 #!/usr/bin/env python | |
2 """Tests for significantly_different.""" | |
3 | |
4 import json | |
5 import os | |
6 import sys | |
7 import unittest | |
8 | |
9 # pylint: disable=relative-import | |
10 import significantly_different | |
11 | |
12 | |
13 class SignificantlyDifferentTest(unittest.TestCase): | |
14 | |
15 def setUp(self): | |
16 self.conda_path = None | |
17 try: | |
18 import scipy # pylint: disable=unused-variable | |
19 self.conda_path = sys.executable | |
20 except ImportError: | |
21 if os.path.exists(os.path.expanduser('~/conda-test/bin/python')): | |
22 self.conda_path = os.path.expanduser('~/conda-test/bin/python') | |
23 | |
24 def test_basic_case(self): | |
25 try: | |
26 sample_A = [1, 2, 3, 3, 2, 1] | |
27 sample_B = [1, 2, 2, 2, 5, 0] | |
28 results = significantly_different.main( | |
29 ['', json.dumps(sample_A), json.dumps(sample_B), '0.05'], | |
30 self.conda_path) | |
31 except significantly_different.ScipyNotInstalledError: | |
32 # This is meant to let presubmit pass on CQ bots :( because they don't | |
33 # have scipy either directly or thorugh anaconda. | |
34 return | |
35 | |
36 self.assertAlmostEqual( | |
37 0.40073980338363635, | |
38 results['mann_p_value']) | |
39 self.assertEqual(results['first_sample'], sample_A) | |
40 self.assertEqual(results['second_sample'], sample_B) | |
41 | |
42 def test_single_value(self): | |
43 try: | |
44 sample_A = [1, 1, 1, 1, 1, 1] | |
45 sample_B = [1, 1, 1] | |
46 results = significantly_different.main( | |
47 ['', json.dumps(sample_A), json.dumps(sample_B), '0.05'], | |
48 self.conda_path) | |
49 except significantly_different.ScipyNotInstalledError: | |
50 # This is meant to let presubmit pass on CQ bots :( because they don't | |
51 # have scipy either directly or thorugh anaconda. | |
52 return | |
53 self.assertIsNone(results['mann_p_value']) | |
54 self.assertFalse(results['significantly_different']) | |
55 self.assertEqual(results['first_sample'], sample_A) | |
56 self.assertEqual(results['second_sample'], sample_B) | |
57 | |
58 if __name__ == '__main__': | |
59 unittest.main() | |
OLD | NEW |