|
@@ -0,0 +1,106 @@
|
|
|
+import os
|
|
|
+import sys
|
|
|
+
|
|
|
+myPath = os.path.dirname(os.path.abspath(__file__))
|
|
|
+sys.path.insert(0, myPath + '/../')
|
|
|
+
|
|
|
+from icopy2xls import Mover
|
|
|
+
|
|
|
+input_file_1 = "tests/TestInput/Financial Sample.xlsx"
|
|
|
+input_file_2 = "tests/TestInput/Financial Sample_1.xlsx"
|
|
|
+input_sheet = "Sheet1"
|
|
|
+destination_file = "tests/TestInput/Financial Sample - Output.xlsx"
|
|
|
+output_file = "tests/TestOutput/Financial Sample - Result.xlsx"
|
|
|
+output_sheet = "Sheet1"
|
|
|
+
|
|
|
+if os.path.exists(output_file):
|
|
|
+ os.remove(output_file)
|
|
|
+
|
|
|
+with open(destination_file, 'rb')as file:
|
|
|
+ data = file.read()
|
|
|
+
|
|
|
+with open(output_file, 'wb')as file:
|
|
|
+ file.write(data)
|
|
|
+
|
|
|
+mover = Mover(
|
|
|
+ source_file_path=input_file_1,
|
|
|
+ source_sheet=input_sheet,
|
|
|
+ destination_file_path=output_file,
|
|
|
+ destination_sheet=output_sheet
|
|
|
+ )
|
|
|
+
|
|
|
+
|
|
|
+def test_basic():
|
|
|
+ mover.move()
|
|
|
+ sht = mover.read_xlsx(output_file, output_sheet)
|
|
|
+ assert sht.nrows == 1401 and sht.ncols == 12
|
|
|
+
|
|
|
+
|
|
|
+def test_filters():
|
|
|
+ mover.move(filters={"Country": "Canada"})
|
|
|
+ sht = mover.read_xlsx(output_file, output_sheet)
|
|
|
+ assert sht.nrows == 1541 and sht.ncols == 12
|
|
|
+
|
|
|
+
|
|
|
+def test_filters_multiple():
|
|
|
+ mover.move(filters={"Country": "Canada", "Segment": "Government"})
|
|
|
+ sht = mover.read_xlsx(output_file, output_sheet)
|
|
|
+ assert sht.nrows == 1601 and sht.ncols == 12
|
|
|
+
|
|
|
+
|
|
|
+def test_filters_value_list():
|
|
|
+ mover.move(filters={"Country": ["Canada", "France"]})
|
|
|
+ sht = mover.read_xlsx(output_file, output_sheet)
|
|
|
+ assert sht.nrows == 1881 and sht.ncols == 12
|
|
|
+
|
|
|
+
|
|
|
+def test_process_lines():
|
|
|
+ lines = "3,7-13,25,300-310,1"
|
|
|
+ processed = mover.process_lines(lines)
|
|
|
+ expected = [1, 3, 7, 8, 9, 10, 11, 12, 13, 25, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310]
|
|
|
+ assert len(processed) == 21 and sorted(processed) == expected
|
|
|
+
|
|
|
+
|
|
|
+def test_lines():
|
|
|
+ move = Mover(
|
|
|
+ source_file_path=input_file_1,
|
|
|
+ source_sheet=input_sheet,
|
|
|
+ destination_file_path=output_file,
|
|
|
+ destination_sheet=output_sheet,
|
|
|
+ lines="1-10"
|
|
|
+ )
|
|
|
+ move.move()
|
|
|
+ sht = mover.read_xlsx(output_file, output_sheet)
|
|
|
+ assert sht.nrows == 1891 and sht.ncols == 12
|
|
|
+
|
|
|
+
|
|
|
+def test_add_missing():
|
|
|
+ move = Mover(
|
|
|
+ source_file_path=input_file_1,
|
|
|
+ source_sheet=input_sheet,
|
|
|
+ destination_file_path=output_file,
|
|
|
+ destination_sheet=output_sheet,
|
|
|
+ lines="1-10"
|
|
|
+ )
|
|
|
+ move.move(add_missing_columns=True)
|
|
|
+ sht = mover.read_xlsx(output_file, output_sheet)
|
|
|
+ assert sht.nrows == 1901 and sht.ncols == 16
|
|
|
+
|
|
|
+
|
|
|
+def test_multiple_inputs():
|
|
|
+ move = Mover(
|
|
|
+ source_file_path=[input_file_1, input_file_2],
|
|
|
+ source_sheet=input_sheet,
|
|
|
+ destination_file_path=output_file,
|
|
|
+ destination_sheet=output_sheet,
|
|
|
+ lines="10,21-30"
|
|
|
+ )
|
|
|
+ move.move()
|
|
|
+ sht = mover.read_xlsx(output_file, output_sheet)
|
|
|
+ assert sht.nrows == 1923 and sht.ncols == 16
|
|
|
+
|
|
|
+
|
|
|
+def test_read_xlsx():
|
|
|
+ sht = mover.read_xlsx(output_file, output_sheet)
|
|
|
+ assert sht.nrows == 1923 and sht.ncols == 16
|
|
|
+
|