def test_yaml_from_filepath(fs, yaml_contents): filepath = "foo.yaml" yaml_contents, expected_contents = yaml_contents fs.create_file(filepath, contents=yaml_contents) result = load_from_filepath(filepath) assert result == expected_contents
def __init__(self, container: Container, filepath: str, path: str = None): content = load_from_filepath(filepath) self.path = path if path: content = sget(content, path) content = list(iterate_over_values(content)) super().__init__(container, initial_content=content)
def test_json_from_filepath(fs, json_contents): filepath = "foo.json" json_contents, expected_contents = json_contents fs.create_file(filepath, contents=json_contents) result = load_from_filepath(filepath) assert result == expected_contents
def test_ini_from_filepath(fs, ini_contents): filepath = "foo.ini" ini_contents, expected_contents = ini_contents fs.create_file(filepath, contents=ini_contents) result = load_from_filepath(filepath) assert result == expected_contents
def load_from_filepath(cls, filepath): result = load_from_filepath(filepath) repos = {} for obj in iterate_over_values(result): klass = obj.__class__ if klass not in repos: repos[klass] = cls(klass) repos[klass].insert(obj)
def test_load_from_file(): contents = ("---\n" "foo: bar\n") with mock.patch( 'pca.utils.serialization.read_from_file') as mocked_read_from_file: mocked_read_from_file.return_value = contents result = serialization.load_from_filepath('path/to/a/file.yaml') assert result == {'foo': 'bar'} mocked_read_from_file.assert_called_with('path/to/a/file.yaml')
def test_load_from_file(): contents = ( "---\n" "foo: bar\n" ) with mock.patch('pca.utils.serialization.read_from_file') as mocked_read_from_file: mocked_read_from_file.return_value = contents result = serialization.load_from_filepath('path/to/a/file.yaml') assert result == {'foo': 'bar'} mocked_read_from_file.assert_called_with('path/to/a/file.yaml')