Esempio n. 1
0
    def test_datetime_serialization(self):
        d = datetime.datetime.now()
        json_file = JsonFile()
        json_file.data = {"date": d} 
        json_file.save(self.tmpfile)

        json_file2 = JsonFile(self.tmpfile)
        self.assertTrue(isinstance(json_file2.data["date"], datetime.datetime), msg="Datetime value is not deserialized correctly")
Esempio n. 2
0
    def test_locked_loading(self):
        fd = os.fdopen(self.tmpfd, "w")
        fd.write("{}")
        fd.close()
        json_file = JsonFile(self.tmpfile)
        self.assertEqual(json_file.data, {}, msg="Value is not deserialized correctly")

        fd = open(self.tmpfile, "w+")
        fd.write("[]")
        fd.close()
        json_file.refresh()
        self.assertEqual(json_file.data, [], msg="Value is not refreshed correctly")
Esempio n. 3
0
    def test_locked_loading(self):
        fd = os.fdopen(self.tmpfd, "w")
        fd.write("{}")
        fd.close()
        json_file = JsonFile(self.tmpfile)
        self.assertEqual(json_file.data, {},
                         msg="Value is not deserialized correctly")

        fd = open(self.tmpfile, "w+")
        fd.write("[]")
        fd.close()
        json_file.refresh()
        self.assertEqual(json_file.data, [],
                         msg="Value is not refreshed correctly")
Esempio n. 4
0
    def test_datetime_serialization(self):
        d = datetime.datetime.now()
        json_file = JsonFile()
        json_file.data = {"date": d}
        json_file.save(self.tmpfile)

        json_file2 = JsonFile(self.tmpfile)
        self.assertTrue(isinstance(json_file2.data["date"], datetime.datetime),
                        msg="Datetime value is not deserialized correctly")