Exemple #1
0
 def testSample05RelativeErrorCheck09(self):
     """Test Case: Sample05 json files with a relative tolerance of 1e-10. Expect 9 difference identified"""
     A, B = self.setUpSample05()
     relative_error = 1e-10
     json_diff = diff.compare_jsons(A, B, relative_error=relative_error)
     count = len(json_diff.pretty().splitlines())
     self.assertEqual(count, 9)
Exemple #2
0
 def testSample05AbsoluteErrorCheck10(self):
     """Test Case: Sample05 json files with an absolute tolerance of 1e-11. Expect a difference of 9 or greater because of floating point subtraction"""
     A, B = self.setUpSample05()
     absolute_error = 1e-11
     json_diff = diff.compare_jsons(A, B, absolute_error=absolute_error)
     count = len(json_diff.pretty().splitlines())
     self.assertTrue(count >= 9)
Exemple #3
0
 def testCompareJsonsInvalidExtension(self):
     """Test Case: An invalid extension is provided. Raises TypeError because expect .json extension, .py provided"""
     A = os.path.abspath(
         os.path.join(os.path.dirname(__file__), '..', '..', 'bin',
                      'jsondiff.py'))
     relative_error = 1e-8
     with self.assertRaises(TypeError):
         json_diff = diff.compare_jsons(A, A, relative_error=relative_error)
Exemple #4
0
 def testCompareJsonsInvalidPath(self):
     """Test Case: An invalid path to the file and raises FileNotFoundError"""
     A = os.path.abspath(
         os.path.join(os.path.dirname(__file__), 'samples', 'json',
                      'sample05A.json'))
     B = os.path.abspath(
         os.path.join(os.path.dirname(__file__), 'samples', 'json',
                      'sample05', 'sample05B.json'))
     relative_error = 1e-8
     with self.assertRaises(FileNotFoundError):
         json_diff = diff.compare_jsons(A, B, relative_error=relative_error)
Exemple #5
0
 def testCompareJsonsAbsoluteErrorNoDifference(self):
     """Test Case: the two json files are equal when using absolute error"""
     A = os.path.abspath(
         os.path.join(os.path.dirname(__file__), 'samples', 'json',
                      'sample05', 'sample05A.json'))
     absolute_error = 1e-10
     json_diff = diff.compare_jsons(A, A, absolute_error=absolute_error)
     is_equal = False
     if len(json_diff) == 0:
         is_equal = True
     self.assertEqual(is_equal, True)
Exemple #6
0
 def testCompareJsonsAbsoluteErrorDifference(self):
     """Test Case: the two json files are different when using absolute error"""
     A = os.path.abspath(
         os.path.join(os.path.dirname(__file__), 'samples', 'json',
                      'sample05', 'sample05A.json'))
     B = os.path.abspath(
         os.path.join(os.path.dirname(__file__), 'samples', 'json',
                      'sample05', 'sample05B.json'))
     absolute_error = 1e-10
     json_diff = diff.compare_jsons(A, B, absolute_error=absolute_error)
     has_differences = False
     if len(json_diff) != 0:
         has_differences = True
     self.assertEqual(has_differences, True)
Exemple #7
0
 def testCompareJsonsInvalidTolerance(self):
     """Test Case: An invalid tolerance since both relative error or absolute error were provided and raises ValueError"""
     A = os.path.abspath(
         os.path.join(os.path.dirname(__file__), 'samples', 'json',
                      'sample05', 'sample05A.json'))
     B = os.path.abspath(
         os.path.join(os.path.dirname(__file__), 'samples', 'json',
                      'sample05', 'sample05B.json'))
     relative_error = 1e-8
     absolute_error = 1e-10
     with self.assertRaises(ValueError):
         json_diff = diff.compare_jsons(A,
                                        A,
                                        relative_error=relative_error,
                                        absolute_error=absolute_error)