def test_write(self): document = {'Disco': {1: 'Beatdown', 2: 'Elysium'}} json_file_interface.write(self.get_temp_file('test_write.json'), document) self.assertTrue( filecmp.cmp(self.get_temp_file('test_write.json'), self.get_static_file('test_write.json')), 'Files do not match')
def test_write_empty_file(self): document = {} file_path = self.get_temp_file('test_write_empty_file.json') json_file_interface.write(file_path, document) self.assertTrue( filecmp.cmp(file_path, self.get_static_file('test_write_empty_file.json')), 'Files do not match')
def test_write_list_contents(self): document = ['Disco', 'Fever'] file_path = self.get_temp_file('test_write_list_contents.json') json_file_interface.write(file_path, document) # A list should just translate to a linear series of YAML keys self.assertTrue( filecmp.cmp(file_path, self.get_static_file('test_write_list_contents.json')), 'Files do not match')
def test_write_string_contents(self): document = 'Ugh' file_path = self.get_temp_file('test_write_string_contents.json') json_file_interface.write(file_path, document) # Despite not being a dictionary, this writes valid YAML to the file - the result being a single YAML key self.assertTrue( filecmp.cmp( file_path, self.get_static_file('test_write_string_contents.json')), 'Files do not match')
def test_write_overwrite(self): document = {'Disco': {1: 'Beatdown', 2: 'Elysium'}} json_file_interface.write( self.get_temp_file('test_write_overwrite.json'), document) self.assertEqual(len(document['Disco']), 2, 'Number of entries is incorrect') document['Disco'][3] = 'Fever' json_file_interface.write( self.get_temp_file('test_write_overwrite.json'), document) self.assertEqual(document['Disco'][3], 'Fever', 'Third entry is incorrect')