Created
March 11, 2021 23:21
-
-
Save Penguin2600/bca88971424a13f45d3560acf0e60f45 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
import jsonpatch | |
import json | |
class ProveJsonPatchIsBusted(unittest.TestCase): | |
def setUp(self): | |
self.dict1 = { | |
'd1': | |
{ | |
'abcd': {'2020': 10.7, '2021': 1.0, '2022': 0.0} | |
}, | |
'time': {'granularity': 'yes'}, | |
'cvb': {'scalar': 1} | |
} | |
self.dict2 = { | |
'd1': | |
{ | |
'abcd': {'total': 61.0} | |
}, | |
'time': {'total': True}, | |
'cvb': {'scalar': 1} | |
} | |
def test_diffing_dicts(self): | |
# Generate patch against python dicts | |
patch_obj = jsonpatch.make_patch(self.dict1, self.dict2) | |
# Apply patch to original python dict | |
result = patch_obj.apply(self.dict1) | |
# Assert Original and patched are Equal | |
# Alarmingly Passes due to python truthiness (True == 1.0) | |
self.assertTrue(self.dict2 == result) | |
# Assert Patch applied typing as intended | |
# Fails because 1.0 isnt a boolean | |
print(f"\n\noutput: {result}\n\n") | |
self.assertTrue(isinstance(result['time']['total'], bool)) | |
if __name__ == "__main__": | |
unittest.main(verbosity=2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment