Use json equality rather than raw text
It turns out sometimes json will serialize differently given the same python structure. A check of the two parsed data structures will detect changes more reliably. Change-Id: Id165b36c0fa0fa89730c3507444a41c68bd70fb3 Closes-Bug: #1320262
This commit is contained in:
parent
96248ee8a7
commit
dc35d20358
|
@ -57,16 +57,13 @@ def store(name, content):
|
|||
os.rename(new.name, dest_path)
|
||||
|
||||
if not changed:
|
||||
with open(dest_path) as now:
|
||||
if os.path.exists(last_path):
|
||||
with open(last_path) as then:
|
||||
for now_line in now:
|
||||
then_line = then.next()
|
||||
if then_line != now_line:
|
||||
changed = True
|
||||
break
|
||||
else:
|
||||
changed = True
|
||||
if os.path.exists(last_path):
|
||||
with open(last_path) as then:
|
||||
then_value = json.load(then)
|
||||
if then_value != content:
|
||||
changed = True
|
||||
else:
|
||||
changed = True
|
||||
return (changed, dest_path)
|
||||
|
||||
|
||||
|
|
|
@ -83,5 +83,19 @@ class TestCache(testtools.TestCase):
|
|||
self.assertThat(list_list, matchers.IsInstance(list))
|
||||
self.assertIn(path, list_list)
|
||||
|
||||
def test_cache_ignores_json_inequality(self):
|
||||
content1 = u'{"a": "value-a", "b": "value-b"}'
|
||||
content2 = u'{"b": "value-b", "a": "value-a"}'
|
||||
value1 = json.loads(content1)
|
||||
value2 = json.loads(content2)
|
||||
self.assertEqual(value1, value2)
|
||||
(changed, path) = cache.store('content', value1)
|
||||
self.assertTrue(changed)
|
||||
cache.commit('content')
|
||||
(changed, path) = cache.store('content', value1)
|
||||
self.assertFalse(changed)
|
||||
(changed, path) = cache.store('content', value2)
|
||||
self.assertFalse(changed)
|
||||
|
||||
def test_commit_no_cache(self):
|
||||
self.assertEqual(None, cache.commit('neversaved'))
|
||||
|
|
Loading…
Reference in New Issue