def test_None_to_json(self): filename = self.temp_text() write_json(filename, None) actual = read_json(filename) self.assertIsNone(actual)
def test_write_file(self): filename = self.temp_text() obj = Klass("value", 345) write_json(filename, obj) actual = read_json(filename) self.assertEquals("value", actual.member1) self.assertEquals(345, actual.member2)
def load(self): items = convertible.read_json(self.filename) if not items: return [] # TODO: Remove it after 16.05 for item in items: if not hasattr(item, 'protocol'): item.protocol = 'TCP' return items
def load(self): items = convertible.read_json(self.filename) if not items: return [] return items
def load(self): if not os.path.isfile(self.filename): raise Exception('{} does not exist'.format(self.filename)) obj = convertible.read_json(self.filename) return obj
def test_read_file(self): filename = self.temp_text('{"member1": "value", "member2": 345}') actual = read_json(filename) self.assertEquals("value", actual.member1) self.assertEquals(345, actual.member2)
def test_from_new_lines_and_spaces(self): filename = self.temp_text(' \n \n \n') actual = read_json(filename) self.assertIsNone(actual)
def test_from_empty_file(self): filename = self.temp_text() actual = read_json(filename) self.assertIsNone(actual)
def test_from_non_existing_file(self): filename = self.temp_text('{"member1": "value", "member2": 345}') os.remove(filename) actual = read_json(filename) self.assertIsNone(actual)
def list(self): apps_data = convertible.read_json(self.filename, models.Apps) if not apps_data: return [] return apps_data.apps