def test_json_data(self): os.unlink(self.tmpfile) concurrently.json_create(self.tmpfile, {'key': 'val'}) with concurrently.json_data(self.tmpfile) as d: self.assertEqual(d['key'], 'val') d['key'] = 'updated' self.assertEqual('updated', concurrently.json_get(self.tmpfile)['key'])
def test_create_json(self): '''we can create a json file''' # we fail if it already exists with self.assertRaises(OSError): concurrently.json_create(self.tmpfile, {}) os.unlink(self.tmpfile) # we can create concurrently.json_create(self.tmpfile, {})
def test_json_get(self): # we fail if file doesn't exist os.unlink(self.tmpfile) with self.assertRaises(OSError): concurrently.json_get(self.tmpfile, False) # we can also pass if requested os.unlink(self.tmpfile) self.assertEqual({}, concurrently.json_get(self.tmpfile, True)) # we can read a good file concurrently.json_create(self.tmpfile, {'key': 'val'}) data = concurrently.json_get(self.tmpfile) self.assertEqual('val', data['key'])