Skip to content

Commit

Permalink
Add tests for comparison of file contents
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton Khodak committed Feb 8, 2018
1 parent 3d286a4 commit ccd6197
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 5 deletions.
1 change: 1 addition & 0 deletions tests/test-data/cores.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2
55 changes: 50 additions & 5 deletions tests/test_compare.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import unittest
from cwltest import CompareFail
from cwltest.utils import compare_file
from cwltest.utils import compare_file, compare


class TestCompareFile(unittest.TestCase):
class TestCompare(unittest.TestCase):

def test_general(self):
def compare_success(self, expected, actual):
try:
compare(expected, actual)
except CompareFail:
self.fail("Comparison failed unexpectedly")


class TestCompareFile(TestCompare):

def test_compare_file(self):
expected = {
"location": "cores.txt",
"size": 2,
Expand All @@ -21,8 +30,44 @@ def test_general(self):
"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")
self.fail("File comparison failed unexpectedly")

def test_compare_contents_success(self):
expected = {
"location": "cores.txt",
"size": 2,
"class": "File",
"contents": "2\n"
}

actual = {
"basename": "cores.txt",
"checksum": "sha1$7448d8798a4380162d4b56f9b452e2f6f9e24e7a",
"class": "File",
"location": "file:///var/folders/8x/2df05_7j20j6r8y81w4qf43r0000gn/T/tmpG0EkrS/cores.txt",
"path": "tests/test-data/cores.txt",
"size": 2
}
self.compare_success(expected, actual)

def test_compare_contents_failure(self):
expected = {
"location": "cores.txt",
"size": 2,
"class": "File",
"contents": "2"
}

actual = {
"basename": "cores.txt",
"checksum": "sha1$7448d8798a4380162d4b56f9b452e2f6f9e24e7a",
"class": "File",
"location": "file:///var/folders/8x/2df05_7j20j6r8y81w4qf43r0000gn/T/tmpG0EkrS/cores.txt",
"path": "tests/test-data/cores.txt",
"size": 2
}
with self.assertRaises(CompareFail):
compare_file(expected, actual)

0 comments on commit ccd6197

Please sign in to comment.