Skip to content

Reordered test assertions #2407

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

Merged
merged 4 commits into from
Feb 24, 2021
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion tests/cluecode/cluecode_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def closure_test_function(*args, **kwargs):
'\ntest file: file://' + test_file + '\n'
) + expected_yaml

assert expected_yaml == results_yaml
assert results_yaml == expected_yaml

data_file = test.data_file
test_file = test.test_file
Expand Down
32 changes: 16 additions & 16 deletions tests/cluecode/test_copyrights_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,51 +20,51 @@ class TestTextPreparation(FileBasedTesting):

def test_strip_leading_numbers(self):
a = '2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)] on win32'
assert a == copyrights_module.strip_leading_numbers(a)
assert copyrights_module.strip_leading_numbers(a) == a

a = '26 6 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)] on 12'
expected = '2010, 18:46:32) [MSC v.1500 32 bit (Intel)] on 12'
assert expected == copyrights_module.strip_leading_numbers(a)
assert copyrights_module.strip_leading_numbers(a) == expected

def test_prepare_text_line(self):
cp = 'test (C) all rights reserved'
result = copyrights_module.prepare_text_line(cp)
assert 'test (c) all rights reserved' == result
assert result == 'test (c) all rights reserved'

def test_prepare_text_line_debian(self):
cp = 'Parts Copyright (c) 1992 <s>Uri Blumentha<s>l, I</s>BM</s>'
result = copyrights_module.prepare_text_line(cp)
assert 'Parts Copyright (c) 1992 Uri Blumenthal, IBM' == result
assert result == 'Parts Copyright (c) 1992 Uri Blumenthal, IBM'

def test_prepare_text_line_does_not_truncate_transliterable_unicode(self):
cp = u'Muła'
result = copyrights_module.prepare_text_line(cp)
assert 'Mula' == result
assert result == 'Mula'

def test_strip_markup(self):
cp = 'Parts Copyright (c) 1992 <s>Uri Blumentha<s>l, I</s>BM</s>'
result = copyrights_module.strip_markup(cp)
assert 'Parts Copyright (c) 1992 Uri Blumenthal, IBM' == result
assert result == 'Parts Copyright (c) 1992 Uri Blumenthal, IBM'

def test_prepare_text_line_removes_C_comments(self):
cp = '/* Copyright 1996-2005, 2008-2011 by */'
result = copyrights_module.prepare_text_line(cp)
assert 'Copyright 1996-2005, 2008-2011 by' == result
assert result == 'Copyright 1996-2005, 2008-2011 by'

def test_prepare_text_line_removes_C_comments2(self):
cp = '/* David Turner, Robert Wilhelm, and Werner Lemberg. */'
result = copyrights_module.prepare_text_line(cp)
assert 'David Turner, Robert Wilhelm, and Werner Lemberg.' == result
assert result == 'David Turner, Robert Wilhelm, and Werner Lemberg.'

def test_prepare_text_line_removes_Cpp_comments(self):
cp = '// David Turner, Robert Wilhelm, and Werner Lemberg. */'
result = copyrights_module.prepare_text_line(cp)
assert 'David Turner, Robert Wilhelm, and Werner Lemberg.' == result
assert result == 'David Turner, Robert Wilhelm, and Werner Lemberg.'

def test_prepare_text_line_does_not_damage_urls(self):
cp = 'copyright (c) 2000 World Wide Web Consortium, http://www.w3.org'
result = copyrights_module.prepare_text_line(cp)
assert 'copyright (c) 2000 World Wide Web Consortium, http://www.w3.org' == result
assert result == 'copyright (c) 2000 World Wide Web Consortium, http://www.w3.org'

def test_is_end_of_statement(self):
line = ''' "All rights reserved\\n"'''
Expand All @@ -75,7 +75,7 @@ def test_candidate_lines_simple(self):
lines = [(1, ' test (C) all rights reserved')]
result = list(copyrights_module.candidate_lines(lines))
expected = [[(1, ' test (C) all rights reserved')]]
assert expected == result
assert result == expected

def test_candidate_lines_complex(self):
lines = '''
Expand Down Expand Up @@ -119,7 +119,7 @@ def test_candidate_lines_complex(self):
]

result = list(copyrights_module.candidate_lines(enumerate(lines, 1)))
assert expected == result
assert result == expected

def test_is_candidates_should_not_select_line_with_bare_full_year(self):
line = '2012'
Expand Down Expand Up @@ -204,7 +204,7 @@ def test_detect(self):
'(c) 2008',
]
copyrights, _, _ = cluecode_test_utils.copyright_detector(location)
assert expected == copyrights
assert copyrights == expected

def test_detect_with_lines(self):
location = self.get_test_loc('copyrights_basic/essential_smoke-ibm_c.c')
Expand All @@ -216,7 +216,7 @@ def test_detect_with_lines(self):
('copyrights', u'(c) 2008', 8, 8)
]
results = list(copyrights_module.detect_copyrights(location))
assert expected == results
assert results == expected

def test_detect_with_lines_only_holders(self):
location = self.get_test_loc('copyrights_basic/essential_smoke-ibm_c.c')
Expand All @@ -225,7 +225,7 @@ def test_detect_with_lines_only_holders(self):
('holders', u'Eclipse, IBM and others', 8, 8)
]
results = list(copyrights_module.detect_copyrights(location, copyrights=False, authors=False))
assert expected == results
assert results == expected


def check_detection_with_lines(expected, test_file):
Expand All @@ -241,7 +241,7 @@ def check_detection_with_lines(expected, test_file):
)

results = [(statement, start, end) for _t, statement, start, end in detections]
assert expected == results
assert results == expected


class TestCopyrightLinesDetection(FileBasedTesting):
Expand Down
6 changes: 3 additions & 3 deletions tests/cluecode/test_copyrights_fosso.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def build_copyright_test_methods_with_fossology_data():
expected_files.append(tf)
files_to_test.append(tf.replace('_raw', ''))

assert sorted(test_files) == sorted(files_to_test + expected_files)
assert sorted(files_to_test + expected_files) == sorted(test_files)

copyregex = re.compile('<s>(.*?)</s>', re.DOTALL | re.UNICODE) # NOQA
for expected_file, test_file in zip(expected_files, files_to_test):
Expand Down Expand Up @@ -132,14 +132,14 @@ def copyright_test_method(self):
copyrights, _authors, _holders = cluecode_test_utils.copyright_detector(test_file_loc)

try:
assert expected == copyrights
assert copyrights == expected
except:
failure_trace = [
'Failed to detect copyright in: file://' + test_file_loc, '\n',
'expected as file://' + expected_file_loc, '\n',
] + expected

assert failure_trace == copyrights
assert copyrights == failure_trace

return copyright_test_method

Expand Down
Loading