Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let regression tests fail on any mismatch #247

Merged
merged 1 commit into from
May 18, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions tests/pefile_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def _load_test_files(self):
def test_pe_image_regression_test(self):
"""Run through all the test files and make sure they run correctly"""

failed = False
for idx, pe_filename in enumerate(self.test_files):
if pe_filename.endswith('fake_PE_no_read_permissions_issue_53'):
continue
Expand All @@ -44,8 +45,9 @@ def test_pe_image_regression_test(self):
pe_file_dict_data = pe.dump_dict() # Make sure that it does not fail
pe_file_data = pe_file_data.replace('\n\r', '\n')
except Exception as excp:
print('Failed processing [%s]' % os.path.basename(pe_filename))
raise
print('Failed processing [%s] (%s)' % (os.path.basename(pe_filename), excp))
failed = True
continue

control_data_filename = '%s.dmp' % pe_filename

Expand All @@ -70,7 +72,7 @@ def test_pe_image_regression_test(self):
lines_to_ignore = 0

if control_data_hash != pe_file_data_hash:
print('Hash differs for [%s]' % os.path.basename(pe_filename))
print('\nHash differs for [%s]' % os.path.basename(pe_filename))

diff = difflib.ndiff(
control_data.decode('utf-8').splitlines(), pe_file_data.splitlines())
Expand Down Expand Up @@ -109,8 +111,9 @@ def test_pe_image_regression_test(self):
lines_to_ignore))

# Do the diff again to store it for analysis.
diff = difflib.unified_diff(
control_data.decode('utf-8').splitlines(), pe_file_data.splitlines())
diff = list(difflib.unified_diff(
control_data.decode('utf-8').splitlines(), pe_file_data.splitlines(),
fromfile="expected", tofile="new"))
error_diff_f = open('error_diff.txt', 'ab')
error_diff_f.write(
b'\n________________________________________\n')
Expand All @@ -119,18 +122,14 @@ def test_pe_image_regression_test(self):
error_diff_f.write(
'\n'.join([l for l in diff if not l.startswith(' ')]).encode('utf-8', 'backslashreplace'))
error_diff_f.close()
print('\n'.join(diff))
print('Diff saved to: error_diff.txt')

if diff_lines_removed_count == 0:
try:
self.assertEqual(control_data.decode('utf-8'), pe_file_data)
except AssertionError:
diff = difflib.unified_diff(
control_data.decode('utf-8').splitlines(), pe_file_data.splitlines())
raise AssertionError('\n'.join(diff))
failed = True

os.sys.stdout.write('[%d]' % (len(self.test_files) - idx))
os.sys.stdout.flush()
if failed:
raise AssertionError("One or more errors occured")


def test_selective_loading_integrity(self):
Expand Down