Пример #1
0
    def test_parsing_env_vars_in_toml(self):
        """Test that environment variables get parsed in the TOML file."""
        # Some useful variables.
        DEFAULT_VAL, DESIRED_VAL = "Christopher", "Walken"
        DUMMY_DEFINITION = "<test definition>"

        # Create a dummy default option.
        config._create_option(
            "_test.tomlTest",
            description="This option tests the TOML parser.",
            default_val=DEFAULT_VAL,
        )
        config.get_config_options(force_reparse=True)
        self.assertEqual(config.get_option("_test.tomlTest"), DEFAULT_VAL)
        self.assertEqual(
            config.get_where_defined("_test.tomlTest"), ConfigOption.DEFAULT_DEFINITION
        )

        os.environ["TEST_ENV_VAR"] = DESIRED_VAL

        # Override it with some TOML
        NEW_TOML = """
            [_test]
            tomlTest="env:TEST_ENV_VAR"
        """
        config._update_config_with_toml(NEW_TOML, DUMMY_DEFINITION)
        self.assertEqual(config.get_option("_test.tomlTest"), DESIRED_VAL)
        self.assertEqual(config.get_where_defined("_test.tomlTest"), DUMMY_DEFINITION)
Пример #2
0
    def test_parsing_toml(self):
        """Test config._update_config_with_toml()."""
        # Some useful variables.
        DUMMY_VAL_1, DUMMY_VAL_2 = "Christopher", "Walken"
        DUMMY_DEFINITION = "<test definition>"

        # Create a dummy default option.
        config._create_option(
            "_test.tomlTest",
            description="This option tests the TOML parser.",
            default_val=DUMMY_VAL_1,
        )
        config.get_config_options(force_reparse=True)
        self.assertEqual(config.get_option("_test.tomlTest"), DUMMY_VAL_1)
        self.assertEqual(
            config.get_where_defined("_test.tomlTest"), ConfigOption.DEFAULT_DEFINITION
        )

        # Override it with some TOML
        NEW_TOML = (
            """
            [_test]
            tomlTest="%s"
        """
            % DUMMY_VAL_2
        )
        config._update_config_with_toml(NEW_TOML, DUMMY_DEFINITION)
        self.assertEqual(config.get_option("_test.tomlTest"), DUMMY_VAL_2)
        self.assertEqual(config.get_where_defined("_test.tomlTest"), DUMMY_DEFINITION)
Пример #3
0
    def test_parsing_env_vars_in_toml(self):
        """Test that environment variables get parsed in the TOML file."""
        # Some useful variables.
        DEFAULT_VAL, DESIRED_VAL = 'Christopher', 'Walken'
        DUMMY_DEFINITION = '<test definition>'

        # Create a dummy default option.
        config._create_option('_test.tomlTest',
                              description='This option tests the TOML parser.',
                              default_val=DEFAULT_VAL)
        self.assertEqual(config.get_option('_test.tomlTest'), DEFAULT_VAL)
        self.assertEqual(config.get_where_defined('_test.tomlTest'),
                         ConfigOption.DEFAULT_DEFINITION)

        os.environ['TEST_ENV_VAR'] = DESIRED_VAL

        # Override it with some TOML
        NEW_TOML = """
            [_test]
            tomlTest="env:TEST_ENV_VAR"
        """
        config._update_config_with_toml(NEW_TOML, DUMMY_DEFINITION)
        self.assertEqual(config.get_option('_test.tomlTest'), DESIRED_VAL)
        self.assertEqual(config.get_where_defined('_test.tomlTest'),
                         DUMMY_DEFINITION)
Пример #4
0
 def test_update_config_with_toml(self):
     self.assertEqual(True, config.get_option("client.caching"))
     toml = textwrap.dedent("""
        [client]
        caching = false
     """)
     config._update_config_with_toml(toml, "test")
     self.assertEqual(False, config.get_option("client.caching"))
Пример #5
0
 def test_update_config_with_toml(self):
     self.assertEqual(True, config.get_option('client.caching'))
     toml = textwrap.dedent('''
        [client]
        caching = false
     ''')
     config._update_config_with_toml(toml, 'test')
     self.assertEqual(False, config.get_option('client.caching'))
Пример #6
0
    def test_parsing_toml(self):
        """Test config._update_config_with_toml()."""
        # Some useful variables.
        DUMMY_VAL_1, DUMMY_VAL_2 = 'Christopher', 'Walken'
        DUMMY_DEFINITION = '<test definition>'

        # Create a dummy default option.
        config._create_option('_test.tomlTest',
                              description='This option tests the TOML parser.',
                              default_val=DUMMY_VAL_1)
        self.assertEqual(config.get_option('_test.tomlTest'), DUMMY_VAL_1)
        self.assertEqual(config.get_where_defined('_test.tomlTest'),
                         ConfigOption.DEFAULT_DEFINITION)

        # Override it with some TOML
        NEW_TOML = """
            [_test]
            tomlTest="%s"
        """ % DUMMY_VAL_2
        config._update_config_with_toml(NEW_TOML, DUMMY_DEFINITION)
        self.assertEqual(config.get_option('_test.tomlTest'), DUMMY_VAL_2)
        self.assertEqual(config.get_where_defined('_test.tomlTest'),
                         DUMMY_DEFINITION)