コード例 #1
0
ファイル: test_app.py プロジェクト: mvaaltola/NewGAN-Manager
class Test_Profile_Manager(unittest.TestCase):
    def setUp(self):
        self.pm = Profile_Manager("No Profile", "newganmanager/testing/")

    def test_delete_profile(self):
        pass

    def test_create_profile(self):

        self.pm.create_profile("test")
        cfg = Config_Manager().load_config("newganmanager/testing/.user/cfg.json")
        self.assertFalse(cfg["Profile"]["test"])
        self.assertTrue(os.path.isfile("newganmanager/testing/.user/test.json"))
        self.assertTrue(os.path.isfile("newganmanager/testing/.user/test.xml"))
        prf_cfg = Config_Manager().load_config("newganmanager/testing/.user/test.json")
        self.assertEqual(prf_cfg["imgs"], {})
        self.assertEqual(prf_cfg["ethnics"], {})
        self.assertEqual(prf_cfg["img_dir"], "")
        self.assertEqual(prf_cfg["rtf"], "")

    def test_load_profile(self):
        pass

    def test_swap_xml(self):
        self.pm.swap_xml("test", "No Profile", "newganmanager/test/", "newganmanager/test/")
        with open("newganmanager/testing/.user/test.xml", "r") as test_xml:
            self.assertEqual(test_xml.read(), "OUTSIDE")
        with open("newganmanager/test/config.xml", "r") as config_xml:
            self.assertEqual(config_xml.read(), "")

    def test_get_ethnic(self):
        self.assertEqual(self.pm.get_ethnic("GER"), "Central European")
        self.assertEqual(self.pm.get_ethnic("ZZZ"), None)

    def test_switching_profiles_with_invalid_path(self):

        self.pm.swap_xml("test", "No Profile", "newganmanager/invalid/", "newganmanager/test/")
        self.pm.swap_xml("No Profile", "test", "newganmanager/test/", "newganmanager/invalid/")

    def test_migrate_function(self):
      newganmanager/testing/
        cfg = Config_Manager().load_config("newganmanager/testing/.config/cfg.json")
        cfg["Profile"] = {"testmig" : False, "No Profile": True}
        Config_Manager().save_config("newganmanager/testing/.config/cfg.json", cfg)
        self.pm.eth_cfg = cfg
        f = open("newganmanager/testing/.config/testmig.xml", "a")
        f.write("TESTMIGXML!")
        f.close()
        f = open("newganmanager/testing/.config/testmig.json", "a")
        f.write("{'text': 'TESTMIGJSON!'}")
        f.close()
        self.pm.migrate_config()
        res_cfg = Config_Manager().load_config("newganmanager/testing/.config/cfg.json")
        self.assertNotIn("Profile", res_cfg)
        self.assertIn("Ethnics", res_cfg)
        usr_cfg = Config_Manager().load_config("newganmanager/testing/.user/cfg.json")
        self.assertNotIn("Ethnics", usr_cfg)
        self.assertIn("Profile", usr_cfg)
        self.assertTrue(os.path.isfile("newganmanager/testing/.user/testmig.json"))
        self.assertTrue(os.path.isfile("newganmanager/testing/.user/testmig.xml"))
        self.assertFalse(os.path.isfile("newganmanager/testing/.config/testmig.json"))
        self.assertFalse(os.path.isfile("newganmanager/testing/.config/testmig.xml"))
コード例 #2
0
class Test_Profile_Manager(unittest.TestCase):
    def setUp(self):
        shutil.copyfile("newganmanager/.user/default_cfg.json", "newganmanager/testing/.user/cfg.json")
        self.pm = Profile_Manager("No Profile", "newganmanager/testing")

    def test_delete_profile(self):
        cfg = Config_Manager().load_config("newganmanager/testing/.user/cfg.json")
        cfg["Profile"] = {"testmig" : False, "No Profile": True}
        Config_Manager().save_config("newganmanager/testing/.user/cfg.json", cfg)
        f = open("newganmanager/testing/.user/testmig.xml", "a")
        f.write("TESTMIGXML!")
        f.close()
        f = open("newganmanager/testing/.user/testmig.json", "a")
        f.write("{'text': 'TESTMIGJSON!'}")
        f.close()
        self.pm.config = Config_Manager().load_config("newganmanager/testing/.user/cfg.json")
        self.pm.delete_profile("testmig")
        usr_cfg = Config_Manager().load_config("newganmanager/testing/.user/cfg.json")
        self.assertNotIn("testmig", usr_cfg["Profile"])
        self.assertIn("No Profile", usr_cfg["Profile"])
        self.assertFalse(os.path.isfile("newganmanager/testing/.user/testmig.json"))
        self.assertFalse(os.path.isfile("newganmanager/testing/.user/testmig.xml"))

    def test_create_profile(self):
        self.pm.create_profile("test")
        cfg = Config_Manager().load_config("newganmanager/testing/.user/cfg.json")
        self.assertFalse(cfg["Profile"]["test"])
        self.assertTrue(os.path.isfile("newganmanager/testing/.user/test.json"))
        self.assertTrue(os.path.isfile("newganmanager/testing/.user/test.xml"))
        prf_cfg = Config_Manager().load_config("newganmanager/testing/.user/test.json")
        self.assertEqual(prf_cfg["imgs"], {})
        self.assertEqual(prf_cfg["ethnics"], {})
        self.assertEqual(prf_cfg["img_dir"], "")
        self.assertEqual(prf_cfg["rtf"], "")

    def test_load_profile(self):
        cfg = Config_Manager().load_config("newganmanager/testing/.user/cfg.json")
        cfg["Profile"] = {"testmig" : False, "No Profile": True}
        Config_Manager().save_config("newganmanager/testing/.user/cfg.json", cfg)
        f = open("newganmanager/testing/.user/testmig.xml", "a")
        f.write("TESTMIGXML!")
        f.close()
        f = open("newganmanager/testing/.user/testmig.json", "a")
        f.write("{\"img_dir\": \"newganmanager/test/\"}")
        f.close()
        self.pm.config = cfg
        self.pm.root_dir = "newganmanager/testing"
        self.pm.load_profile("testmig")
        self.assertEqual(self.pm.cur_prf, "testmig")
        self.assertEqual(self.pm.prf_cfg["img_dir"], "newganmanager/test/")
        with open("newganmanager/test/config.xml", "r") as cfg_xml:
            data = cfg_xml.read()
            self.assertEqual(data, "TESTMIGXML!")
        self.assertTrue(self.pm.config["Profile"]["testmig"])
        self.assertFalse(self.pm.config["Profile"]["No Profile"])

    def test_swap_xml(self):
        self.pm.swap_xml("test", "No Profile", "newganmanager/test/", "newganmanager/test/")
        with open("newganmanager/testing/.user/test.xml", "r") as test_xml:
            self.assertEqual(test_xml.read(), "OUTSIDE")
        with open("newganmanager/test/config.xml", "r") as config_xml:
            self.assertEqual(config_xml.read(), "")

    def test_get_ethnic(self):
        self.assertEqual(self.pm.get_ethnic("GER"), "Central European")
        self.assertEqual(self.pm.get_ethnic("ZZZ"), None)

    def test_switching_profiles_with_invalid_path(self):
        self.pm.swap_xml("test", "No Profile", "newganmanager/invalid/", "newganmanager/test/")
        self.pm.swap_xml("No Profile", "test", "newganmanager/test/", "newganmanager/invalid/")

    def test_migrate_function(self):
        shutil.copytree("newganmanager/.config/", "../.config/")
        shutil.copy("newganmanager/.user/No Profile.json", "../.config/No Profile.json")
        shutil.copy("newganmanager/.user/No Profile.xml", "../.config/No Profile.xml")
        cfg = Config_Manager().load_config("../.config/cfg.json")
        cfg["Profile"] = {"testmig" : False, "No Profile": True}
        Config_Manager().save_config("../.config/cfg.json", cfg)
        f = open("../.config/testmig.xml", "a")
        f.write("TESTMIGXML!")
        f.close()
        f = open("../.config/testmig.json", "a")
        f.write("{'text': 'TESTMIGJSON!'}")
        f.close()
        self.pm.migrate_config()
        res_cfg = Config_Manager().load_config("newganmanager/testing/.config/cfg.json")
        self.assertNotIn("Profile", res_cfg)
        self.assertIn("Ethnics", res_cfg)
        usr_cfg = Config_Manager().load_config("newganmanager/testing/.user/cfg.json")
        self.assertNotIn("Ethnics", usr_cfg)
        self.assertIn("Profile", usr_cfg)
        self.assertTrue(os.path.isfile("newganmanager/testing/.user/testmig.json"))
        self.assertTrue(os.path.isfile("newganmanager/testing/.user/testmig.xml"))
        self.assertFalse(os.path.isfile("../.config/testmig.json"))
        self.assertFalse(os.path.isfile("../.config/testmig.xml"))
        self.assertFalse(os.path.isdir("../.config"))

    def tearDown(self):
        shutil.rmtree("newganmanager/testing/.config/")
        shutil.copytree("newganmanager/.config/", "newganmanager/testing/.config/")
        shutil.rmtree("newganmanager/testing/.user/")
        shutil.copytree("newganmanager/.user/", "newganmanager/testing/.user/")
        with open("newganmanager/test/config.xml", "w") as cfg:
            cfg.write('OUTSIDE')