Skip to content

Commit

Permalink
Add first unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton Khodak committed Feb 8, 2018
1 parent c2636fe commit 05ef85b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
8 changes: 6 additions & 2 deletions cwltest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from concurrent.futures import ThreadPoolExecutor
from six.moves import range
from six.moves import zip
from typing import Any, Dict, List
from typing import Any, Dict, List, Text

from cwltest.utils import compare, CompareFail, TestResult

Expand All @@ -39,7 +39,9 @@

templock = threading.Lock()


def prepare_test_command(args, i, tests):
# type: (argparse.Namespace, int, List[Dict[str, str]]) -> List[str]
t = tests[i]
test_command = [args.tool]
test_command.extend(args.args)
Expand Down Expand Up @@ -82,7 +84,7 @@ def run_test(args, i, tests, timeout):
else:
suffix = "\n"
try:
test_command=prepare_test_command(args, i, tests)
test_command = prepare_test_command(args, i, tests)

sys.stderr.write("%sTest [%i/%i] %s\n" % (prefix, i + 1, len(tests), suffix))
sys.stderr.flush()
Expand Down Expand Up @@ -146,6 +148,7 @@ def run_test(args, i, tests, timeout):

return TestResult((1 if fail_message else 0), outstr, outerr, duration, args.classname, fail_message)


def arg_parser(): # type: () -> argparse.ArgumentParser
parser = argparse.ArgumentParser(description='Compliance tests for cwltool')
parser.add_argument("--test", type=str, help="YAML file describing test cases", required=True)
Expand All @@ -169,6 +172,7 @@ def arg_parser(): # type: () -> argparse.ArgumentParser
"Defaults to 900 sec (15 minutes)")
return parser


def main(): # type: () -> int

args = arg_parser().parse_args(sys.argv[1:])
Expand Down
2 changes: 2 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
[mypy]

[mypy-ruamel.*]
ignore_errors = True
28 changes: 28 additions & 0 deletions tests/test_compare.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import unittest
from cwltest import CompareFail
from cwltest.utils import compare_file


class TestCompareFile(unittest.TestCase):

def test_general(self):
expected = {
"location": "cores.txt",
"size": 2,
"class": "File",
"checksum": "sha1$7448d8798a4380162d4b56f9b452e2f6f9e24e7a"
}

actual = {
"basename": "cores.txt",
"checksum": "sha1$7448d8798a4380162d4b56f9b452e2f6f9e24e7a",
"class": "File",
"location": "file:///var/folders/8x/2df05_7j20j6r8y81w4qf43r0000gn/T/tmpG0EkrS/cores.txt",
"path": "/var/folders/8x/2df05_7j20j6r8y81w4qf43r0000gn/T/tmpG0EkrS/cores.txt",
"size": 2
}

try:
compare_file(expected, actual)
except CompareFail:
self.fail("File comparison failed unexpectedly")

0 comments on commit 05ef85b

Please sign in to comment.