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