コード例 #1
0
    def test_save_and_load(self):
        # test for dict with warning:

        # save a file to disk to test it:
        data = {"wuwu": {"warning": {"warning1", "warning2"}}}
        GenderNounDataHandler.save_to_disk(data, "test.gdn")
        self.assertEqual(data, GenderNounDataHandler.load_from_disk("test.gdn"))

        # test for dict without warning:

        # save a file to disk to test it:
        data = {"wuwu": {"fufu": "wawa"}}
        GenderNounDataHandler.save_to_disk(data, "test.gdn")
        self.assertEqual(data, GenderNounDataHandler.load_from_disk("test.gdn"))

        # test for words with underscores:
        data = {"fu_fu": {"wawa": "wuwu"}}
        GenderNounDataHandler.save_to_disk(data, "test.gdn")
        self.assertEqual(data, GenderNounDataHandler.load_from_disk("test.gdn"))

        # test for a mixture:

        # save a file to disk to test it:
        data = {"wuwu": {"warning": {"warning1", "warning2"}}, "wa_wa": {"fufu": "wawa"}}
        GenderNounDataHandler.save_to_disk(data, "test.gdn")
        self.assertEqual(data, GenderNounDataHandler.load_from_disk("test.gdn"))

        # finally delete the file:
        os.remove("test.gdn")
コード例 #2
0
    def test_save_to_disk(self):
        # test for dict with warning:

        # save a file to disk to test it:
        data_in_file = {"wuwu": {"warning": ["warning1", "warning2"]}}
        data_loaded = {"wuwu": {"warning": {"warning1", "warning2"}}}
        GenderNounDataHandler.save_to_disk(data_loaded, "test.gdn")
        with open("test.gdn", "r") as test_file:
            self.assertEqual(json.loads(test_file.read()), data_in_file)

        # test for dict without warning:

        # save a file to disk to test it:
        data_in_file = {"wuwu": {"fufu": "wawa"}}
        data_loaded = data_in_file
        GenderNounDataHandler.save_to_disk(data_loaded, "test.gdn")
        with open("test.gdn", "r") as test_file:
            self.assertEqual(json.loads(test_file.read()), data_in_file)

        # test for a mixture:

        # save a file to disk to test it:
        data_in_file = {"wuwu": {"warning": ["warning1", "warning2"]}, "wawa": {"fufu": "wawa"}}
        data_loaded = {"wuwu": {"warning": {"warning1", "warning2"}}, "wawa": {"fufu": "wawa"}}
        GenderNounDataHandler.save_to_disk(data_loaded, "test.gdn")
        with open("test.gdn", "r") as test_file:
            self.assertEqual(json.loads(test_file.read()), data_in_file)

        # finally delete the file:
        os.remove("test.gdn")