Skip to content

Commit d0a160f

Browse files
committed
Reorder tests assertions as result == expected
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
1 parent 36106a7 commit d0a160f

19 files changed

Lines changed: 455 additions & 455 deletions

src/commoncode/cliutils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,13 +243,13 @@ def fixed_width_file_name(path, max_length=25):
243243
244244
For example:
245245
>>> fwfn = fixed_width_file_name('0123456789012345678901234.c')
246-
>>> assert '0123456789...5678901234.c' == fwfn
246+
>>> assert fwfn == '0123456789...5678901234.c'
247247
>>> fwfn = fixed_width_file_name('some/path/0123456789012345678901234.c')
248-
>>> assert '0123456789...5678901234.c' == fwfn
248+
>>> assert fwfn == '0123456789...5678901234.c'
249249
>>> fwfn = fixed_width_file_name('some/sort.c')
250-
>>> assert 'sort.c' == fwfn
250+
>>> assert fwfn == 'sort.c'
251251
>>> fwfn = fixed_width_file_name('some/123456', max_length=5)
252-
>>> assert '' == fwfn
252+
>>> assert fwfn == ''
253253
"""
254254
if not path:
255255
return ''

src/commoncode/testcase.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ def file_cmp(file1, file2, ignore_line_endings=False):
269269
f2c = f2.read()
270270
if ignore_line_endings:
271271
f2c = b'\n'.join(f2c.splitlines(False))
272-
assert f1c == f2c
272+
assert f2c == f1c
273273

274274

275275
def make_non_readable(location):

tests/test_cliutils.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,66 +42,66 @@ def mycli():
4242
xyz
4343
End
4444
'''
45-
assert expected == result.output
45+
assert result.output == expected
4646

4747

4848
class TestFixedWidthFilename(FileDrivenTesting):
4949

5050
def test_fixed_width_file_name_with_file_name_larger_than_max_length_is_shortened(self):
5151
test = fixed_width_file_name('0123456789012345678901234.c', 25)
5252
expected = '0123456789...5678901234.c'
53-
assert expected == test
53+
assert test == expected
5454

5555
def test_fixed_width_file_name_with_file_name_smaller_than_max_length_is_not_shortened(self):
5656
file_name = '0123456789012345678901234.c'
5757
test = fixed_width_file_name(file_name, max_length=50)
58-
assert file_name == test
58+
assert test == file_name
5959

6060
def test_fixed_width_file_name_with_file_name_at_max_length_is_not_shortened(self):
6161
test = fixed_width_file_name('01234567890123456789012.c', 25)
6262
expected = '01234567890123456789012.c'
63-
assert expected == test
63+
assert test == expected
6464

6565
def test_fixed_width_file_name_with_file_name_smaller_than_max_length_not_shortened(self):
6666
test = fixed_width_file_name('0123456789012345678901.c', 25)
6767
expected = '0123456789012345678901.c'
68-
assert expected == test
68+
assert test == expected
6969

7070
def test_fixed_width_file_name_with_none_filename_return_empty_string(self):
7171
test = fixed_width_file_name(None, 25)
7272
expected = ''
73-
assert expected == test
73+
assert test == expected
7474

7575
def test_fixed_width_file_name_without_extension(self):
7676
test = fixed_width_file_name('012345678901234567890123456', 25)
7777
expected = '01234567890...67890123456'
78-
assert expected == test
78+
assert test == expected
7979

8080
def test_fixed_width_file_name_with_posix_path_without_shortening(self):
8181
test = fixed_width_file_name('C/Documents_and_Settings/Boki/Desktop/head/patches/drupal6/drupal.js', 25)
8282
expected = 'drupal.js'
83-
assert expected == test
83+
assert test == expected
8484

8585
def test_fixed_width_file_name_with_posix_path_with_shortening(self):
8686
test = fixed_width_file_name('C/Documents_and_Settings/Boki/Desktop/head/patches/drupal6/012345678901234567890123.c', 25)
8787
expected = '0123456789...4567890123.c'
88-
assert expected == test
88+
assert test == expected
8989

9090
def test_fixed_width_file_name_with_win_path_without_shortening(self):
9191
test = fixed_width_file_name('C\\:Documents_and_Settings\\Boki\\Desktop\\head\\patches\\drupal6\\drupal.js', 25)
9292
expected = 'drupal.js'
93-
assert expected == test
93+
assert test == expected
9494

9595
def test_fixed_width_file_name_with_win_path_with_shortening(self):
9696
test = fixed_width_file_name('C\\:Documents_and_Settings\\Boki\\Desktop\\head\\patches\\drupal6\\012345678901234567890123.c', 25)
9797
expected = '0123456789...4567890123.c'
98-
assert expected == test
98+
assert test == expected
9999

100100
def test_fixed_width_file_name_with_very_small_file_name_and_long_extension(self):
101101
test = fixed_width_file_name('abc.abcdef', 5)
102102
# FIXME: what is expected is TBD
103103
expected = ''
104-
assert expected == test
104+
assert test == expected
105105

106106

107107
class TestGroupedHelpCommand(FileDrivenTesting):

tests/test_codec.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,62 +18,62 @@ class TestCodec(TestCase):
1818
def test_bin_to_num_basic(self):
1919
expected = 123
2020
result = bin_to_num(b'{')
21-
assert expected == result
21+
assert result == expected
2222

2323
def test_bin_to_num_zero(self):
2424
expected = 0
2525
result = bin_to_num(b'\x00')
26-
assert expected == result
26+
assert result == expected
2727

2828
def test_bin_to_num_large_number(self):
2929
expected = 432346237462348763
3030
result = bin_to_num(b'\x06\x00\x00\x9c\xbf\xeb\x83\xdb')
31-
assert expected == result
31+
assert result == expected
3232

3333
def test_bin_to_num_and_num_to_bin_is_idempotent(self):
3434
expected = 432346237462348763
3535
result = bin_to_num(num_to_bin(432346237462348763))
36-
assert expected == result
36+
assert result == expected
3737

3838
def test_num_to_bin_basic(self):
3939
expected = b'{'
4040
result = num_to_bin(123)
41-
assert expected == result
41+
assert result == expected
4242

4343
def test_num_to_bin_zero(self):
4444
expected = b'\x00'
4545
result = num_to_bin(0)
46-
assert expected == result
46+
assert result == expected
4747

4848
def test_num_to_bin_large_number(self):
4949
expected = b'\x06\x00\x00\x9c\xbf\xeb\x83\xdb'
5050
result = num_to_bin(432346237462348763)
51-
assert expected == result
51+
assert result == expected
5252

5353
def test_num_to_bin_bin_to_num_is_idempotent(self):
5454
expected = b'\x06\x00\x00\x9c\xbf\xeb\x83\xdb'
5555
result = num_to_bin(bin_to_num(b'\x06\x00\x00\x9c\xbf\xeb\x83\xdb'))
56-
assert expected == result
56+
assert result == expected
5757

5858
def test_urlsafe_b64encode_int_zero(self):
59-
assert b'AA==' == urlsafe_b64encode_int(0)
59+
assert urlsafe_b64encode_int(0) == b'AA=='
6060

6161
def test_urlsafe_b64encode_int_basic(self):
62-
assert b'HKq1w7M=' == urlsafe_b64encode_int(123123123123)
62+
assert urlsafe_b64encode_int(123123123123) == b'HKq1w7M='
6363

6464
def test_urlsafe_b64encode_int_limit_8bits_255(self):
65-
assert b'_w==' == urlsafe_b64encode_int(255)
65+
assert urlsafe_b64encode_int(255) == b'_w=='
6666

6767
def test_urlsafe_b64encode_int_limit_8bits_256(self):
68-
assert b'AQA=' == urlsafe_b64encode_int(256)
68+
assert urlsafe_b64encode_int(256) == b'AQA='
6969

7070
def test_urlsafe_b64encode_int_adds_no_padding_for_number_that_are_multiple_of_6_bits(self):
71-
assert b'____________' == urlsafe_b64encode_int(0xFFFFFFFFFFFFFFFFFF)
72-
assert 8 == len(urlsafe_b64encode_int(0xFFFFFFFFFFFF))
71+
assert urlsafe_b64encode_int(0xFFFFFFFFFFFFFFFFFF) == b'____________'
72+
assert len(urlsafe_b64encode_int(0xFFFFFFFFFFFF)) == 8
7373

7474
def test_urlsafe_b64encode_int_very_large_number(self):
7575
b64 = (b'QAAAAAAgAAAAAQAACAAAAAAAAAAAAAAkAAIAAAAAAAAAAAAAAACAAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAIAAAAAAAAAAAAAAAAAAAAiAAAAAAAIAAAAAAAAAAAAAAEAACAAAAAAAA=')
7676
expected = b64
7777
num = 2678771517966886466622496485850735537232223496190189203248435106535830319026141316924949516664780383591425235756710588949364368366679435700855700642969357960349427980681242720502045830438444033569999428606714388704082526548154984676817460705606960919023941301616034362869262429593297635158449513824256
7878
result = urlsafe_b64encode_int(num)
79-
assert expected == result
79+
assert result == expected

tests/test_command.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ def test_execute_can_handle_non_ascii_output(self):
3030
rc, stdout, stderr = command.execute(
3131
python, ['-c', 'print("non ascii: été just passed it !")']
3232
)
33-
assert '' == stderr
34-
assert 'non ascii: ete just passed it !' == stdout
35-
assert 0 == rc
33+
assert stderr == ''
34+
assert stdout == 'non ascii: ete just passed it !'
35+
assert rc == 0
3636
# do not throw exception
3737
stdout.encode('ascii')
3838

@@ -41,9 +41,9 @@ def test_execute_(self):
4141
rc, stdout, stderr = command.execute(
4242
python, ['-c', 'print("foobar")']
4343
)
44-
assert '' == stderr
45-
assert 'foobar' == stdout
46-
assert 0 == rc
44+
assert stderr == ''
45+
assert stdout == 'foobar'
46+
assert rc == 0
4747
# do not throw exception
4848
stdout.encode('ascii')
4949

@@ -52,9 +52,9 @@ def test_execute2(self):
5252
rc, stdout, stderr = command.execute2(
5353
python, ['-c', 'print("foobar")']
5454
)
55-
assert '' == stderr
56-
assert 'foobar' == stdout
57-
assert 0 == rc
55+
assert stderr == ''
56+
assert stdout == 'foobar'
57+
assert rc == 0
5858
# do not throw exception
5959
stdout.encode('ascii')
6060

@@ -64,51 +64,51 @@ def test_update_path_var_on_linux(self):
6464

6565
new_path = b'foo\xb1bar'
6666
updated_path = command.update_path_var(existing_path_var, new_path)
67-
assert 'foo\udcb1bar:/usr/bin:/usr/local' == updated_path
67+
assert updated_path == 'foo\udcb1bar:/usr/bin:/usr/local'
6868

6969
new_path = u'/bin/foo\udcb1bar'
7070
updated_path = command.update_path_var(updated_path, new_path)
71-
assert '/bin/foo\udcb1bar:foo\udcb1bar:/usr/bin:/usr/local' == updated_path
71+
assert updated_path == '/bin/foo\udcb1bar:foo\udcb1bar:/usr/bin:/usr/local'
7272

7373
new_path = b'/bin/foo\xb1bar'
7474
updated_path = command.update_path_var(updated_path, new_path)
75-
assert '/bin/foo\udcb1bar:foo\udcb1bar:/usr/bin:/usr/local' == updated_path
75+
assert updated_path == '/bin/foo\udcb1bar:foo\udcb1bar:/usr/bin:/usr/local'
7676

7777
new_path = u'foo\udcb1bar'
7878
updated_path = command.update_path_var(updated_path, new_path)
79-
assert '/bin/foo\udcb1bar:foo\udcb1bar:/usr/bin:/usr/local' == updated_path
79+
assert updated_path == '/bin/foo\udcb1bar:foo\udcb1bar:/usr/bin:/usr/local'
8080

8181
new_path = b'foo\xb1bar'
8282
updated_path = command.update_path_var(updated_path, new_path)
83-
assert '/bin/foo\udcb1bar:foo\udcb1bar:/usr/bin:/usr/local' == updated_path
83+
assert updated_path == '/bin/foo\udcb1bar:foo\udcb1bar:/usr/bin:/usr/local'
8484

8585
@skipIf(not on_mac, 'Mac only')
8686
def test_update_path_var_on_mac(self):
8787
existing_path_var = '/usr/bin:/usr/local'
8888

8989
new_path = u'foo\udcb1bar'
9090
updated_path = command.update_path_var(existing_path_var, new_path)
91-
assert 'foo\udcb1bar:/usr/bin:/usr/local' == updated_path
91+
assert updated_path == 'foo\udcb1bar:/usr/bin:/usr/local'
9292

9393
new_path = b'/bin/foo\xb1bar'
9494
updated_path = command.update_path_var(updated_path, new_path)
95-
assert '/bin/foo\udcb1bar:foo\udcb1bar:/usr/bin:/usr/local' == updated_path
95+
assert updated_path == '/bin/foo\udcb1bar:foo\udcb1bar:/usr/bin:/usr/local'
9696

9797
new_path = u'foo\udcb1bar'
9898
updated_path = command.update_path_var(updated_path, new_path)
99-
assert '/bin/foo\udcb1bar:foo\udcb1bar:/usr/bin:/usr/local' == updated_path
99+
assert updated_path == '/bin/foo\udcb1bar:foo\udcb1bar:/usr/bin:/usr/local'
100100

101101
@skipIf(not on_windows, 'Windows only')
102102
def test_update_path_var_on_windows(self):
103103
existing_path_var = u'c:\\windows;C:Program Files'
104104

105105
new_path = u'foo\udcb1bar'
106106
updated_path = command.update_path_var(existing_path_var, new_path)
107-
assert u'foo\udcb1bar;c:\\windows;C:Program Files' == updated_path
107+
assert updated_path == u'foo\udcb1bar;c:\\windows;C:Program Files'
108108

109109
new_path = u'foo\udcb1bar'
110110
updated_path = command.update_path_var(updated_path, new_path)
111-
assert u'foo\udcb1bar;c:\\windows;C:Program Files' == updated_path
111+
assert updated_path == u'foo\udcb1bar;c:\\windows;C:Program Files'
112112

113113
def test_searchable_paths(self):
114114
d1 = self.get_temp_dir('foo')
@@ -123,25 +123,25 @@ def test_searchable_paths(self):
123123
# macOS somehow adds a /private to the paths in the CI as a side-
124124
# effect of calling "realpath" and likely resolving links
125125
expected = f'/private{d1}', f'/private{d2}', f'/private{d2}', f'/private{d1}'
126-
assert command.searchable_paths(env_vars=env_vars) == expected
126+
assert expected == command.searchable_paths(env_vars=env_vars)
127127

128128
def test_find_in_path(self):
129129
d1 = self.get_temp_dir('foo')
130130
d2 = self.get_temp_dir('bar')
131131
filename = 'baz'
132132

133-
assert command.find_in_path(filename, searchable_paths=(d1, d2,)) == None
133+
assert None == command.find_in_path(filename, searchable_paths=(d1, d2,))
134134

135135
f2 = os.path.join(d2, filename)
136136
with open(f2, 'w') as o:
137137
o.write('some')
138138

139-
assert command.find_in_path(filename, searchable_paths=(d1, d2,)) == f2
140-
assert command.find_in_path(filename, searchable_paths=(d2, d1,)) == f2
139+
assert f2 == command.find_in_path(filename, searchable_paths=(d1, d2,))
140+
assert f2 == command.find_in_path(filename, searchable_paths=(d2, d1,))
141141

142142
f1 = os.path.join(d1, filename)
143143
with open(f1, 'w') as o:
144144
o.write('some')
145145

146-
assert command.find_in_path(filename, searchable_paths=(d1, d2,)) == f1
147-
assert command.find_in_path(filename, searchable_paths=(d2, d1,)) == f2
146+
assert f1 == command.find_in_path(filename, searchable_paths=(d1, d2,))
147+
assert f2 == command.find_in_path(filename, searchable_paths=(d2, d1,))

tests/test_date.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def as_yyyymmdd(s):
3636

3737
now = datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ')
3838
result = commoncode.date.get_file_mtime(test_file)
39-
assert as_yyyymmdd(now) == as_yyyymmdd(result)
39+
assert as_yyyymmdd(result) == as_yyyymmdd(now)
4040

4141
def test_get_file_mtime_for_a_modified_file(self):
4242
test_file = self.get_temp_file()
@@ -45,12 +45,12 @@ def test_get_file_mtime_for_a_modified_file(self):
4545
m_ts = (24 * 3600) * 134 + (24 * 3600 * 365) * 22
4646
# setting modified time to expected values
4747
os.utime(test_file, (m_ts, m_ts))
48-
assert expected == commoncode.date.get_file_mtime(test_file)
48+
assert commoncode.date.get_file_mtime(test_file) == expected
4949

5050
def test_get_file_mtime_for_a_modified_file_2(self):
5151
test_file = self.get_temp_file()
5252
open(test_file, 'w').close()
5353
# setting modified time to expected values
5454
expected = u'2011-01-06 14:35:00'
5555
os.utime(test_file, (1294324500, 1294324500))
56-
assert expected == commoncode.date.get_file_mtime(test_file)
56+
assert commoncode.date.get_file_mtime(test_file) == expected

tests/test_fileset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class FilesetTest(commoncode.testcase.FileBasedTesting):
1818
def test_load(self):
1919
irf = self.get_test_loc('fileset/scancodeignore.lst')
2020
result = fileset.load(irf)
21-
assert ['/foo/*', '!/foobar/*', 'bar/*', '#comment'] == result
21+
assert result == ['/foo/*', '!/foobar/*', 'bar/*', '#comment']
2222

2323
def test_is_included_basic(self):
2424
assert fileset.is_included('/common/src/', {}, {})

0 commit comments

Comments
 (0)