summaryrefslogtreecommitdiff
path: root/Tools/XlsToCsv/test/run
diff options
context:
space:
mode:
Diffstat (limited to 'Tools/XlsToCsv/test/run')
-rw-r--r--Tools/XlsToCsv/test/run63
1 files changed, 63 insertions, 0 deletions
diff --git a/Tools/XlsToCsv/test/run b/Tools/XlsToCsv/test/run
new file mode 100644
index 0000000..990421c
--- /dev/null
+++ b/Tools/XlsToCsv/test/run
@@ -0,0 +1,63 @@
+#!/usr/bin/env python
+
+import os
+import sys
+import subprocess
+from io import open
+
+PYTHON_VERSIONS = ["2", "3"]
+
+"""
+This test uses sys.stdout.
+That means this test doesn't verify:
+ - file output process
+ - differences from sys.stdout like line terminater
+"""
+
+def compare(case, arguments=[]):
+ failed = False
+ for pyver in PYTHON_VERSIONS:
+ ext = "xlsx"
+ if os.path.exists("test/%s.xlsm" % case):
+ ext = "xlsm"
+
+ if os.name == 'posix':# in case of Linux
+ left = subprocess.check_output(["python%s" %pyver, "./xlsx2csv.py"] + arguments + ["test/%s.%s" %(case, ext)]).decode('utf-8').replace('\r','')
+ elif os.name == 'nt':# in case of Windows
+ # Use py.exe http://blog.python.org/2011/07/python-launcher-for-windows_11.html on Windows
+ left = subprocess.check_output(["py", "-%s" %pyver, "./xlsx2csv.py"] + arguments + ["test/%s.%s" %(case, ext)]).decode('utf-8').replace('\r','')
+ else:
+ print("os.name is unexpected: "+os.name)
+ sys.exit(1)
+
+ f = open("test/%s.csv" %case, "r", encoding="utf-8", newline="")
+ right = f.read().replace('\r','')
+ f.close()
+
+ if left != right:
+ print("FAILED: %s %s" %(case, pyver))
+ print(" actual:", left.replace("\r", "\\r").replace("\n", "\\n"))
+ print(" expected:", right.replace("\r", "\\r").replace("\n", "\\n"))
+ failed = True
+ else:
+ print("OK: %s %s" %(case, pyver))
+ if failed:
+ sys.exit(1)
+
+compare("datetime", ["--dateformat=%Y-%m-%d %H:%M:%S"])
+compare("empty_row")
+compare("junk-small")
+compare("last-column-empty")
+compare("sheets", ["-a"])
+compare("skip_empty_lines", ["-i"])
+compare("twolettercolumns")
+compare("xlsx2csv-test-file")
+compare("escape", ["-e"])
+compare("hyperlinks", ["--hyperlinks"])
+compare("hyperlinks_continous", ["--hyperlinks"])
+compare("namespace")
+compare("float")
+compare("variousdelim", ["--all","--sheetdelimiter=x33", "--lineterminator=\\r", "--delimiter=\\t"])
+compare("utf8")
+compare("no_cell_ids")
+compare("sheets_order", ["-a"])