Skip to content

Instantly share code, notes, and snippets.

@Penguin2600
Created March 11, 2021 23:21
Show Gist options
  • Save Penguin2600/bca88971424a13f45d3560acf0e60f45 to your computer and use it in GitHub Desktop.
Save Penguin2600/bca88971424a13f45d3560acf0e60f45 to your computer and use it in GitHub Desktop.
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