def write_table(file: str, headers: List[str], content: Dict[str, Dict[str, str]]): with safe_open(file, 'w+', newline='') as result_file: w = csv.DictWriter(result_file, fieldnames=headers) w.writeheader() for row_key in sorted(content): print(row_key, end='', file=result_file) w.writerow({column_key: content[row_key].get(column_key, '') for column_key in headers[1:]})
def test_reads_project_file(self): test_dict = {"name": "Project Name"} with safe_open(self.uut._project_file, 'w+') as stream: yaml.dump(test_dict, stream) assert_equals(test_dict, self.uut._yaml)
def test_open_file_creates_directories_implicitly(self): safe_open(self.test_file, 'w+').close() assert isfile(self.test_file)
def test_reads_version_file(self): test_dict = {"revision": "42"} with safe_open(self.uut._version_file, 'w+') as stream: yaml.dump(test_dict, stream) assert_equals(test_dict, self.uut._yaml)