Example #1
0
    def test_None_to_json(self):
        filename = self.temp_text()

        write_json(filename, None)

        actual = read_json(filename)
        self.assertIsNone(actual)
Example #2
0
    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)
Example #3
0
    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
Example #4
0
    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
Example #5
0
 def load(self):
     items = convertible.read_json(self.filename)
     if not items:
         return []
     return items
Example #6
0
 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
Example #7
0
    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)
Example #8
0
 def test_from_new_lines_and_spaces(self):
     filename = self.temp_text(' \n \n  \n')
     actual = read_json(filename)
     self.assertIsNone(actual)
Example #9
0
 def test_from_empty_file(self):
     filename = self.temp_text()
     actual = read_json(filename)
     self.assertIsNone(actual)
Example #10
0
 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)
Example #11
0
 def list(self):
     apps_data = convertible.read_json(self.filename, models.Apps)
     if not apps_data:
         return []
     return apps_data.apps
Example #12
0
    def load(self):
        items = convertible.read_json(self.filename)
        if not items:
            return []

        return items
Example #13
0
 def list(self):
     apps_data = convertible.read_json(self.filename, models.Apps)
     if not apps_data:
         return []
     return apps_data.apps