Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from bartfeenstra/assert-paths
Increase coverage for asserting backed up and restored data is not corrupt
- Loading branch information
Showing
10 changed files
with
376 additions
and
260 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +0,0 @@ | ||
import os | ||
|
||
|
||
def assert_path(test, actual_path, expected_path): | ||
"""Assert two actual and expected directory paths are identical. | ||
:param test: unittest.TestCase | ||
:param actual_path: str | ||
:param expected_path: str | ||
:raise: AssertionError | ||
""" | ||
_assert_path(test, actual_path, expected_path) | ||
_assert_path(test, expected_path, actual_path) | ||
|
||
|
||
def _assert_path(test, actual_path, expected_path): | ||
"""Assert the contents of an actual directory appear in another. | ||
:param test: unittest.TestCase | ||
:param actual_path: str | ||
:param expected_path: str | ||
:raise: AssertionError | ||
""" | ||
actual_path = actual_path.rstrip('/') + '/' | ||
expected_path = expected_path.rstrip('/') + '/' | ||
try: | ||
for expected_dir_path, child_dir_names, child_file_names in os.walk(expected_path): | ||
actual_dir_path = os.path.join( | ||
actual_path, expected_dir_path[len(expected_path):]) | ||
for child_file_name in child_file_names: | ||
with open(os.path.join(expected_dir_path, child_file_name)) as expected_f: | ||
with open(os.path.join(actual_dir_path, child_file_name)) as actual_f: | ||
assert_file(test, actual_f, expected_f) | ||
except Exception: | ||
raise AssertionError( | ||
'The actual contents under the path `%s` are not equal to the expected contents under `%s`.' % ( | ||
actual_path, expected_path)) | ||
|
||
|
||
def assert_file(test, source_f, target_f): | ||
"""Assert two source and target files are identical. | ||
:param test: unittest.TestCase | ||
:param source_f: File | ||
:param target_f: File | ||
:raise: AssertionError | ||
""" | ||
source_f.seek(0) | ||
target_f.seek(0) | ||
test.assertEquals(source_f.read(), target_f.read()) | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.