コード例 #1
0
    def test_add_config_dir_one_valid_file(self):
        with TempDirectory() as temp_dir:
            config_dir = "test"

            config_files = [
                {
                    'name': os.path.join(config_dir,'foo.yml'),
                    'contents' : {
                        Config.CONFIG_KEY: {}
                    }
                }
            ]

            for config_file in config_files:
                config_file_name = config_file['name']
                config_file_contents = config_file['contents']
                temp_dir.write(
                    config_file_name,
                    bytes(f"{config_file_contents}", 'utf-8')
                )

            config = Config()
            config.add_config(os.path.join(temp_dir.path, config_dir))

            self.assertEqual(config.global_defaults, {})
            self.assertEqual(config.global_environment_defaults, {})
コード例 #2
0
    def test_add_config_dir_one_valid_file_one_invalid_file(self):
        with TempDirectory() as temp_dir:
            config_dir = "test"

            config_files = [
                {
                    'name': os.path.join(config_dir,'foo.yml'),
                    'contents' : {
                        Config.CONFIG_KEY: {}
                    }
                },
                {
                    'name': os.path.join(config_dir,'bad.yml'),
                    'contents' : {
                        'bad': {
                            'implementer': 'bar'
                        }
                    }
                }
            ]

            for config_file in config_files:
                config_file_name = config_file['name']
                config_file_contents = config_file['contents']
                temp_dir.write(
                    config_file_name,
                    bytes(f"{config_file_contents}", 'utf-8')
                )

            config = Config()
            with self.assertRaisesRegex(
                AssertionError,
                r"Failed to add parsed configuration file \(.*\): Failed to add invalid config. Missing expected top level key \(step-runner-config\):"
            ):
                config.add_config(os.path.join(temp_dir.path, config_dir))
コード例 #3
0
 def test_add_config_invalid_type(self):
     config = Config()
     with self.assertRaisesRegex(
         ValueError,
         r"Given config \(True\) is unexpected type \(<class 'bool'>\) not a dictionary, string, or list of former."
     ):
         config.add_config(True)
コード例 #4
0
 def test_add_config_dict_missing_config_key(self):
     config = Config()
     with self.assertRaisesRegex(
             AssertionError,
             r"Failed to add invalid config. Missing expected top level key \(step-runner-config\):"
     ):
         config.add_config({'foo': 'foo'})
コード例 #5
0
    def test_add_two_valid_files(self):
        with TempDirectory() as temp_dir:
            config_dir = "test"

            config_files = [
                {
                    'name': os.path.join(config_dir,'foo.yml'),
                    'contents' : {
                        Config.CONFIG_KEY: {
                            'step-test-foo' : {
                                'implementer': 'foo',
                                'config': {
                                  'f': 'hello1'
                                }
                            }
                        }
                    }
                },
                {
                    'name': os.path.join(config_dir,'bar.yml'),
                    'contents' : {
                        Config.CONFIG_KEY: {
                            'step-test-bar' : {
                                'implementer': 'bar',
                                'config': {
                                  'b': 'hello2'
                                }
                            }
                        }
                    }
                },
            ]

            for config_file in config_files:
                config_file_name = config_file['name']
                config_file_contents = config_file['contents']
                temp_dir.write(
                    config_file_name,
                    bytes(f"{config_file_contents}", 'utf-8')
                )

            config = Config()
            config.add_config(
                [
                    os.path.join(temp_dir.path, config_dir, 'foo.yml'),
                    os.path.join(temp_dir.path, config_dir, 'bar.yml')
                ]
            )

            self.assertEqual(config.global_defaults, {})
            self.assertEqual(config.global_environment_defaults, {})
            self.assertEqual(
                config.get_step_config('step-test-foo').get_sub_step('foo').get_config_value('f'),
                'hello1'
            )
            self.assertEqual(
                config.get_step_config('step-test-bar').get_sub_step('bar').get_config_value('b'),
                'hello2'
            )
コード例 #6
0
 def test_add_config_file_missing_file(self):
     with TempDirectory() as temp_dir:
         config = Config()
         with self.assertRaisesRegex(
             ValueError,
             r"Given config string \(.*\) is not a valid path."
         ):
             config.add_config(os.path.join(temp_dir.path, 'does-not-exist.yml'))
コード例 #7
0
    def test_add_config_dict_valid_basic(self):
        config = Config()
        config.add_config({
            Config.CONFIG_KEY: {}
        })

        self.assertEqual(config.global_defaults, {})
        self.assertEqual(config.global_environment_defaults, {})
コード例 #8
0
 def test_add_config_dir_no_files(self):
     with TempDirectory() as temp_dir:
         config = Config()
         with self.assertRaisesRegex(
             ValueError,
             r"Given config string \(.*\) is a directory with no recursive children files."
         ):
             config.add_config(temp_dir.path)
コード例 #9
0
    def test_add_config_file_invalid_json_or_yaml(self):
        with TempDirectory() as temp_dir:
            config_file_name = "bad"
            config_file_contents = ": blarg this: is {} bad syntax"
            temp_dir.write(config_file_name, bytes(f"{config_file_contents}", 'utf-8'))

            config = Config()
            with self.assertRaisesRegex(
                ValueError,
                r"Error parsing config file \(.*\) as json or yaml"
            ):
                config.add_config(os.path.join(temp_dir.path, config_file_name))
コード例 #10
0
    def test_add_config_file_valid_basic(self):
        with TempDirectory() as temp_dir:
            config_file_name = "foo.json"
            config_file_contents = {Config.CONFIG_KEY: {}}
            temp_dir.write(config_file_name,
                           bytes(f"{config_file_contents}", 'utf-8'))

            config = Config()
            config.add_config(os.path.join(temp_dir.path, config_file_name))

            self.assertEqual(config.global_defaults, {})
            self.assertEqual(config.global_environment_defaults, {})
コード例 #11
0
    def test_merge_valid_global_environment_defaults_same_env_diff_keys(self):
        with TempDirectory() as temp_dir:
            config_dir = "test"

            config_files = [
                {
                    'name': os.path.join(config_dir,'foo.yml'),
                    'contents' : {
                        Config.CONFIG_KEY: {
                            'global-environment-defaults' : {
                                'env1' : {
                                    'foo-key': 'foo'
                                }
                            }
                        }
                    }
                },
                {
                    'name': os.path.join(config_dir,'bar.yml'),
                    'contents' : {
                        Config.CONFIG_KEY: {
                            'global-environment-defaults' : {
                                'env1' : {
                                    'bar-key': 'bar'
                                }
                            }
                        }
                    }
                },
            ]

            for config_file in config_files:
                config_file_name = config_file['name']
                config_file_contents = config_file['contents']
                temp_dir.write(
                    config_file_name,
                    bytes(f"{config_file_contents}", 'utf-8')
                )

            config = Config()
            config.add_config(os.path.join(temp_dir.path, config_dir))
            self.assertEqual(
                ConfigValue.convert_leaves_to_values(
                    config.get_global_environment_defaults_for_environment('env1')
                ),
                {
                    'environment-name': 'env1',
                    'foo-key': 'foo',
                    'bar-key': 'bar'
                }
            )
コード例 #12
0
    def test_add_config_file_missing_config_key(self):
        with TempDirectory() as temp_dir:
            config_file_name = "foo.json"
            config_file_contents = {
                'foo': 'foo'
            }
            temp_dir.write(config_file_name, bytes(f"{config_file_contents}", 'utf-8'))

            config = Config()
            with self.assertRaisesRegex(
                AssertionError,
                r"Failed to add parsed configuration file \(.*\): Failed to add invalid config. Missing expected top level key \(step-runner-config\):"
            ):
                config.add_config(os.path.join(temp_dir.path, config_file_name))
コード例 #13
0
    def test_duplicate_global_environment_default_keys(self):
        with TempDirectory() as temp_dir:
            config_dir = "test"

            config_files = [
                {
                    'name': os.path.join(config_dir,'foo.yml'),
                    'contents' : {
                        Config.CONFIG_KEY: {
                            'global-environment-defaults' : {
                                'env1' : {
                                    'dup-key': 'foo'
                                }
                            }
                        }
                    }
                },
                {
                    'name': os.path.join(config_dir,'bar.yml'),
                    'contents' : {
                        Config.CONFIG_KEY: {
                            'global-environment-defaults' : {
                                'env1' : {
                                    'dup-key': 'bar'
                                }
                            }
                        }
                    }
                },
            ]

            for config_file in config_files:
                config_file_name = config_file['name']
                config_file_contents = config_file['contents']
                temp_dir.write(
                    config_file_name,
                    bytes(f"{config_file_contents}", 'utf-8')
                )

            with self.assertRaisesRegex(
                ValueError,
                r"Error merging global environment \(env1\) defaults: Conflict at dup-key"
            ):
                config = Config()
                config.add_config(os.path.join(temp_dir.path, config_dir))