Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_excute_ng_multiple_src(self):
with pytest.raises(InvalidCount) as execinfo:
try:
# create test file
os.makedirs(self._data_dir)
excel_file = os.path.join(self._data_dir, "test1.xlxs")
open(excel_file, "w").close()
excel_file2 = os.path.join(self._data_dir, "test2.xlxs")
open(excel_file2, "w").close()
# set the essential attributes
instance = ExcelConvert()
Helper.set_property(instance, "logger", LisboaLog.get_logger(__name__))
Helper.set_property(instance, "src_dir", self._data_dir)
Helper.set_property(instance, "src_pattern", "test(.*)\.xlxs")
Helper.set_property(instance, "dest_dir", self._data_dir)
Helper.set_property(instance, "dest_pattern", "test(.*).xlxs")
instance.execute()
finally:
shutil.rmtree(self._data_dir)
assert "must be only one" in str(execinfo.value)
def test_execute_ng_no_multiple_files(self):
# create test files
os.makedirs(self._data_dir)
test1_csv = os.path.join(self._data_dir, "test1.csv")
test2_csv = os.path.join(self._data_dir, "test2.csv")
open(test1_csv, "w").close
open(test2_csv, "w").close
with pytest.raises(InvalidCount) as execinfo:
# set the essential attributes
instance = CsvHeaderConvert()
Helper.set_property(instance, "logger", LisboaLog.get_logger(__name__))
Helper.set_property(instance, "src_dir", self._data_dir)
Helper.set_property(instance, "src_pattern", "test(.*)\.csv")
Helper.set_property(instance, "dest_dir", self._data_dir)
Helper.set_property(instance, "dest_pattern", "test_new.csv")
Helper.set_property(
instance, "headers", [{"key": "new_key"}, {"data": "new_data"}]
)
instance.execute()
shutil.rmtree(self._data_dir)
assert "only one" in str(execinfo.value)
def test_execute_ng_no_multiple_files(self):
# create test files
os.makedirs(self._data_dir)
test1_csv = os.path.join(self._data_dir, "test1.csv")
test2_csv = os.path.join(self._data_dir, "test2.csv")
open(test1_csv, "w").close
open(test2_csv, "w").close
with pytest.raises(InvalidCount) as execinfo:
# set the essential attributes
instance = CsvHeaderConvert()
Helper.set_property(instance, "logger", LisboaLog.get_logger(__name__))
Helper.set_property(instance, "src_dir", self._data_dir)
Helper.set_property(instance, "src_pattern", "test(.*)\.csv")
Helper.set_property(instance, "dest_dir", self._data_dir)
Helper.set_property(instance, "dest_pattern", "test_new.csv")
Helper.set_property(
instance, "headers", [{"key": "new_key"}, {"data": "new_data"}]
)
instance.execute()
shutil.rmtree(self._data_dir)
assert "only one" in str(execinfo.value)
def test_execute_ok(self):
try:
os.makedirs(self._data_dir)
instance = FtpDownload()
Helper.set_property(instance, "logger", LisboaLog.get_logger(__name__))
# use public ftp
Helper.set_property(instance, "host", "test.rebex.net")
Helper.set_property(instance, "user", "demo")
Helper.set_property(instance, "password", "password")
Helper.set_property(instance, "src_dir", "/")
Helper.set_property(instance, "src_pattern", "(.*).txt")
Helper.set_property(instance, "dest_dir", self._data_dir)
instance.execute()
exists_file = os.path.exists(os.path.join(self._data_dir, "readme.txt"))
finally:
shutil.rmtree(self._data_dir)
assert exists_file is True
def test_execute_ok(self):
try:
os.makedirs(self._data_dir)
instance = FtpDownload()
Helper.set_property(instance, "logger", LisboaLog.get_logger(__name__))
# use public ftp
Helper.set_property(instance, "host", "test.rebex.net")
Helper.set_property(instance, "user", "demo")
Helper.set_property(instance, "password", "password")
Helper.set_property(instance, "src_dir", "/")
Helper.set_property(instance, "src_pattern", "(.*).txt")
Helper.set_property(instance, "dest_dir", self._data_dir)
instance.execute()
exists_file = os.path.exists(os.path.join(self._data_dir, "readme.txt"))
finally:
shutil.rmtree(self._data_dir)
assert exists_file is True
def test_execute_ok(self):
try:
# create test file
csv_list = [["key", "data"], ["1", "spam"], ["2", "spam"], ["3", "spam"]]
os.makedirs(self._data_dir)
test_csv = os.path.join(self._data_dir, "test.csv")
with open(test_csv, "w") as t:
writer = csv.writer(t)
writer.writerows(csv_list)
# set the essential attributes
instance = CsvHeaderConvert()
Helper.set_property(instance, "logger", LisboaLog.get_logger(__name__))
Helper.set_property(instance, "src_dir", self._data_dir)
Helper.set_property(instance, "src_pattern", "test\.csv")
Helper.set_property(instance, "dest_dir", self._data_dir)
Helper.set_property(instance, "dest_pattern", "test_new.csv")
Helper.set_property(
instance, "headers", [{"key": "new_key"}, {"data": "new_data"}]
)
instance.execute()
test_new_csv = os.path.join(self._data_dir, "test_new.csv")
with open(test_new_csv, "r") as t:
reader = csv.reader(t)
line = next(reader)
finally:
shutil.rmtree(self._data_dir)
assert line == ["new_key", "new_data"]
def test_execute_ok(self):
try:
# create test file
os.makedirs(self._data_dir)
excel_file = os.path.join(self._data_dir, "test.xlxs")
workbook = xlsxwriter.Workbook(excel_file)
workbook.close()
# set the essential attributes
instance = ExcelConvert()
Helper.set_property(instance, "logger", LisboaLog.get_logger(__name__))
Helper.set_property(instance, "src_dir", self._data_dir)
Helper.set_property(instance, "src_pattern", "test\.xlxs")
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]
def test_execute_ok(self):
try:
os.makedirs(self._data_dir)
instance = HttpDownload()
Helper.set_property(instance, "logger", LisboaLog.get_logger(__name__))
# use Postman echo
Helper.set_property(instance, "src_url", "https://postman-echo.com")
Helper.set_property(instance, "src_pattern", "get?foo1=bar1&foo2=bar2")
Helper.set_property(instance, "dest_dir", self._data_dir)
Helper.set_property(instance, "dest_pattern", "test.result")
instance.execute()
f = open(os.path.join(self._data_dir, "test.result"), "r")
result = f.read()
f.close()
finally:
shutil.rmtree(self._data_dir)
assert "postman-echo.com" in result
def test_execute_ok(self):
try:
os.makedirs(self._data_dir)
instance = HttpDownload()
Helper.set_property(instance, "logger", LisboaLog.get_logger(__name__))
# use Postman echo
Helper.set_property(instance, "src_url", "https://postman-echo.com")
Helper.set_property(instance, "src_pattern", "get?foo1=bar1&foo2=bar2")
Helper.set_property(instance, "dest_dir", self._data_dir)
Helper.set_property(instance, "dest_pattern", "test.result")
instance.execute()
f = open(os.path.join(self._data_dir, "test.result"), "r")
result = f.read()
f.close()
finally:
shutil.rmtree(self._data_dir)
assert "postman-echo.com" in result
def test_execute(self):
STR_UTF8 = "いろはにほへと"
try:
# create test file
os.makedirs(self._data_dir)
test_file = os.path.join(self._data_dir, "test.txt")
with open(test_file, "w") as t:
t.write(STR_UTF8)
# set the essential attributes
instance = FileConvert()
Helper.set_property(instance, "logger", LisboaLog.get_logger(__name__))
Helper.set_property(instance, "src_dir", self._data_dir)
Helper.set_property(instance, "src_pattern", r"test\.txt")
Helper.set_property(instance, "encoding_from", "utf-8")
Helper.set_property(instance, "encoding_to", "utf-16")
instance.execute()
with open(test_file, errors="ignore") as t:
str_utf16 = t.read()
assert str_utf16 != STR_UTF8
# set the essential attributes
instance = FileConvert()
Helper.set_property(instance, "logger", LisboaLog.get_logger(__name__))
Helper.set_property(instance, "src_dir", self._data_dir)
Helper.set_property(instance, "src_pattern", r"test\.txt")