def test_spec(self): p = docstring_to_file(self.DOC_SPEC, "test_spec2.txt") print(p) header_dict, unit_dict = load_spec(p) self.assertEqual(header_dict, {"Инвестиции в основной капитал" : ["I", "bln_rub"]}) self.assertEqual(unit_dict, {"в % к предыдущему периоду" : "rog"}) os.remove(p)
def test_cfg2(): p = docstring_to_file(DOC_SPEC, "test_spec.txt") header_dict, unit_dict = load_spec(p) assert header_dict == {"Инвестиции в основной капитал" : ["I", "bln_rub"]} assert unit_dict == {"в % к предыдущему периоду" : "rog"} if MUST_CLEANUP: delete_file(p)
def test_with_file(self): filename = "_test_yaml_spec_sample.txt" p = docstring_to_file(self.yaml_doc, filename) d1, d2 = load_spec(p) self.assertEqual(d1, self.header_dict) self.assertEqual(d2, self.unit_dict)
def get_spec_and_cfg_varnames(data_folder): csv, spec, cfg = get_filenames(data_folder) segments = load_cfg(cfg) header_dict, unit_dict = load_spec(spec) hdr = unpack_header_dict(header_dict) seg = unpack_segments(segments) return hdr, seg
def test_cfg2(): p = docstring_to_file(DOC_SPEC, "test_spec.txt") header_dict, unit_dict = load_spec(p) assert header_dict == {"Инвестиции в основной капитал": ["I", "bln_rub"]} assert unit_dict == {"в % к предыдущему периоду": "rog"} if MUST_CLEANUP: delete_file(p)
def test_with_file(): filename = "_test_yaml_spec_sample.txt" p = docstring_to_file(yaml_doc, filename) d1, d2 = load_spec(p) assert d1 == header_dict assert d2 == unit_dict delete_file(p)
def get_complete_dicts(data_folder): csv, spec, cfg = get_filenames(data_folder) segments = load_cfg(cfg) header_dict, unit_dict = load_spec(spec) for seg in segments: seg_header_dict = seg[2][0] seg_unit_dict = seg[2][1] header_dict.update(seg_header_dict) unit_dict.update(seg_unit_dict) return header_dict, unit_dict
def test_specification_import_from_yaml_file(self): specpath = self.specfile() header_dict, unit_dict = load_spec(filename=specpath) self.assertEqual(header_dict, self.REF_HEADER_DICT) self.assertEqual(unit_dict, self.REF_UNIT_DICT) os.remove(specpath)
def test_specification_import_from_yaml_file(): specpath = specfile() header_dict, unit_dict = load_spec(filename=specpath) assert header_dict == REF_HEADER_DICT assert unit_dict == REF_UNIT_DICT os.remove(specpath)
def get_labelled_rows_no_segments(raw_data_file, yaml_spec_file): raw_rows = yield_csv_rows(raw_data_file) spec_dicts = load_spec(yaml_spec_file) return raw_to_labelled_rows(raw_rows, spec_dicts)
def test_specs(self): header_dict, unit_dict = load_spec(spec_file()) self.assertEqual(header_dict, ref_header_dict()) self.assertEqual(unit_dict, ref_unit_dict())
def test_specification_import_from_yaml_file(): specpath = specfile() header_dict, unit_dict = load_spec(filename = specpath) assert header_dict == REF_HEADER_DICT assert unit_dict == REF_UNIT_DICT os.remove(specpath)
def test_specs(ref_header_dict, ref_unit_dict, spec_file): header_dict, unit_dict = load_spec(spec_file) assert header_dict == ref_header_dict assert unit_dict == ref_unit_dict
def get_labelled_rows_by_segment(raw_data_file, yaml_spec_file, yaml_cfg_file): raw_rows = list(yield_csv_rows(raw_data_file)) default_dicts = load_spec(yaml_spec_file) segment_specs = load_cfg(yaml_cfg_file) return label_raw_rows_by_segment(raw_rows, default_dicts, segment_specs)
def test_specification_import_from_yaml_file(self): specpath = self.specfile() header_dict, unit_dict = load_spec(filename = specpath) self.assertEqual(header_dict, self.REF_HEADER_DICT) self.assertEqual(unit_dict, self.REF_UNIT_DICT) os.remove(specpath)
def compare_doc_to_spec_dicts(doc, ref_header_dict, ref_unit_dict): specpath = docstring_to_file(doc, 'spec.txt') dicts = load_spec(specpath) assert dicts[0] == ref_header_dict assert dicts[1] == ref_unit_dict os.remove(specpath)