Exemplo n.º 1
0
 def test_config_should_be_singleton(self):
     # override user configuration path, to path which don't exist
     with mock.patch("dmenu_hotkeys.config.USER_CONFIG_PATH",
                     self.user_conf_path):
         config1 = Config()
         config2 = Config()
     self.assertEqual(config1, config2)
Exemplo n.º 2
0
 def test_get_config_when_user_home_config_not_exists(self):
     self.assertFalse(os.path.exists(self.user_conf_path))
     # override user configuration path, to file which don't exist
     with mock.patch("dmenu_hotkeys.config.USER_CONFIG_PATH",
                     self.user_conf_path):
         tested_config_from_src = Config().get_config()._sections
     cfg = ConfigParser()
     cfg.read(DMENU_HOTKEYS_CONFIG_PATH)
     expected_config_from_src = cfg._sections
     self.assertDictEqual(tested_config_from_src, expected_config_from_src)
Exemplo n.º 3
0
    def test_set_config_with_cli_kwargs(self):
        conf_without_cli_kwargs = Config(
            config_path=TEST_CONFIG_PATH).get_config()
        self.assertEqual(conf_without_cli_kwargs.getboolean('OTHERS', 'dots'),
                         False)
        self.assertEqual(
            conf_without_cli_kwargs.getint('OTHERS', 'additional_dots'), 10)
        Config._clean_singleton()  # clean singleton

        conf_with_cli_kwargs = Config(config_path=TEST_CONFIG_PATH,
                                      dots=True,
                                      additional_dots=5).get_config()
        unnecessary_args = 2
        self.assertEqual(
            Config.set_config.__code__.co_argcount - unnecessary_args,
            2,
            msg="Added more kwargs to Config.set_config, correct this test!")
        self.assertEqual(conf_with_cli_kwargs.getboolean('OTHERS', 'dots'),
                         True)
        self.assertEqual(
            conf_with_cli_kwargs.getint('OTHERS', 'additional_dots'), 5)
Exemplo n.º 4
0
    def test_get_config_when_user_home_config_exists(self):
        self.assertFalse(os.path.exists(self.user_conf_path))
        cfg = ConfigParser()
        cfg.read(DMENU_HOTKEYS_CONFIG_PATH)
        cfg.remove_section('OTHERS')
        with open(self.user_conf_path, 'w', encoding='utf-8') as configfile:
            cfg.write(configfile)
        self.assertTrue(os.path.exists(self.user_conf_path))

        # override user configuration path, to file which already exists
        with mock.patch("dmenu_hotkeys.config.USER_CONFIG_PATH",
                        self.user_conf_path):
            tested_config_from_user = Config().get_config()._sections
        expected_config_from_user = cfg._sections
        self.assertDictEqual(tested_config_from_user,
                             expected_config_from_user)
Exemplo n.º 5
0
 def tearDown(self):
     super(TestGetConfig, self).tearDown()
     Config._clean_singleton()  # clean singleton after every test
Exemplo n.º 6
0
 def test_init_config_when_config_path_was_passed(self):
     tested_config = Config(config_path=TEST_CONFIG_PATH).get_config()
     cfg = ConfigParser()
     cfg.read(TEST_CONFIG_PATH)
     expected_arg_path_conf = cfg._sections
     self.assertDictEqual(tested_config._sections, expected_arg_path_conf)
Exemplo n.º 7
0
 def setUp(self):
     super(TestConfigTestCase, self).setUp()
     Config._clean_singleton()
     os.environ["DMENU_HOTKEYS_TEST_CONFIG"] = 'true'
     os.environ["DMENU_HOTKEYS_FIXTURES_PATH"] = os.path.join(
         os.path.dirname(__file__), "fixtures")