def test_excute_ng_multiple_target2(self): with pytest.raises(InvalidCount) as execinfo: try: # create test file os.makedirs(self._data_dir, exist_ok=True) target1_file = os.path.join(self._data_dir, "test1.csv") open(target1_file, "w").close() target2_file = os.path.join(self._data_dir, "test22.csv") open(target2_file, "w").close() target2_file = os.path.join(self._data_dir, "test222.csv") open(target2_file, "w").close() # set the essential attributes instance = CsvMerge() Helper.set_property(instance, "logger", LisboaLog.get_logger(__name__)) Helper.set_property(instance, "src_dir", self._data_dir) Helper.set_property(instance, "src1_pattern", "test1.csv") Helper.set_property(instance, "src2_pattern", "test2(.*).csv") Helper.set_property(instance, "dest_dir", self._data_dir) Helper.set_property(instance, "dest_pattern", "test.csv") instance.execute() finally: shutil.rmtree(self._data_dir) assert "must be only one" in str(execinfo.value)
def test_execute_ok_with_unnamed(self): try: # create test file csv_list1 = [["key", "data"], ["1", "spam"], ["2", "spam"], ["3", "spam"]] os.makedirs(self._data_dir, exist_ok=True) test_csv1 = os.path.join(self._data_dir, "test1.csv") with open(test_csv1, "w") as t1: writer = csv.writer(t1) writer.writerows(csv_list1) csv_list2 = [ ["key", "Unnamed: 0"], ["1", "spam"], ["2", "spam"], ["3", "spam"], ] test_csv2 = os.path.join(self._data_dir, "test2.csv") with open(test_csv2, "w") as t2: writer = csv.writer(t2) writer.writerows(csv_list2) # set the essential attributes instance = CsvMerge() Helper.set_property(instance, "logger", LisboaLog.get_logger(__name__)) Helper.set_property(instance, "src_dir", self._data_dir) Helper.set_property(instance, "src1_pattern", r"test1\.csv") Helper.set_property(instance, "src2_pattern", r"test2\.csv") Helper.set_property(instance, "dest_dir", self._data_dir) Helper.set_property(instance, "dest_pattern", "test.csv") instance.execute() exists_csv = glob(os.path.join(self._data_dir, "test.csv")) finally: shutil.rmtree(self._data_dir) assert "test.csv" in exists_csv[0]