def test_good_write(tmp_path): expected = {'a': 'apple', 'b': 'banana'} output_file = os.path.join(tmp_path, 'generated.yml') write(output_file, expected) with open(output_file, 'r') as check_fn: parsed = parse(check_fn.read()) assert parsed == expected
def test_read_write_roundtrip(datadir, tmp_path): output_file = os.path.join(tmp_path, 'generated.yml') input_file = os.path.join(datadir, 'sample.yml') with open(input_file, 'r') as input_fh: output_data = parse(input_fh.read()) write(output_file, output_data) # If an exception is raised the files contain a diff and the test # will fail. We want to make sure we can write out in the same format # that we read in. subprocess.check_call(['diff', input_file, output_file])
def _parse(self, filename): """ Method to parse the config data :param filename: The fully qualified path to load and parse """ with open(filename, 'r') as file_handle: data = yaml.parse(file_handle.read()) self.config_data = _update(self._config_data, data) self._config_files.append(filename)
def _fetch_yaml(url): """ Fetch remote data and process the text as yaml. :param url: The URL to fetch the data from :return: Parsed yaml data in the form of a dictionary """ ret_data = None raw_data = _raw_fetch(url) if raw_data is not None: ret_data = yaml.parse(raw_data) return ret_data
def test_file_read(datadir): file_to_load = os.path.join(datadir, 'sample.yml') expected = {'a': 1, 'b': 2, 'c': [7, 8, 9]} file_handle = open(file_to_load, 'r') actual = parse(file_handle.read()) assert actual == expected
def test_bad_string(): expected = {} input_str = ':' actual = parse(input_str) assert actual == expected
def test_simple_string(): expected = {'a': 1} input_str = '---\na: 1' actual = parse(input_str) assert actual == expected