Skip to content

Commit 3422211

Browse files
committed
Use pytest asserts
Signed-off-by: Joffrey F <[email protected]>
1 parent 4ff2962 commit 3422211

28 files changed

+1270
-1608
lines changed

tests/integration/api_build_test.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def test_build_from_stringio(self):
4343
if six.PY3:
4444
chunk = chunk.decode('utf-8')
4545
logs += chunk
46-
self.assertNotEqual(logs, '')
46+
assert logs != ''
4747

4848
@requires_api_version('1.8')
4949
def test_build_with_dockerignore(self):
@@ -92,11 +92,10 @@ def test_build_with_dockerignore(self):
9292
if six.PY3:
9393
logs = logs.decode('utf-8')
9494

95-
self.assertEqual(
96-
sorted(list(filter(None, logs.split('\n')))),
97-
sorted(['/test/ignored/subdir/excepted-file',
98-
'/test/not-ignored']),
99-
)
95+
assert sorted(list(filter(None, logs.split('\n')))) == sorted([
96+
'/test/ignored/subdir/excepted-file',
97+
'/test/not-ignored'
98+
])
10099

101100
@requires_api_version('1.21')
102101
def test_build_with_buildargs(self):
@@ -114,7 +113,7 @@ def test_build_with_buildargs(self):
114113
pass
115114

116115
info = self.client.inspect_image('buildargs')
117-
self.assertEqual(info['Config']['User'], 'OK')
116+
assert info['Config']['User'] == 'OK'
118117

119118
@requires_api_version('1.22')
120119
def test_build_shmsize(self):
@@ -152,7 +151,7 @@ def test_build_labels(self):
152151
pass
153152

154153
info = self.client.inspect_image('labels')
155-
self.assertEqual(info['Config']['Labels'], labels)
154+
assert info['Config']['Labels'] == labels
156155

157156
@requires_api_version('1.25')
158157
def test_build_with_cache_from(self):
@@ -309,8 +308,8 @@ def build_squashed(squash):
309308

310309
non_squashed = build_squashed(False)
311310
squashed = build_squashed(True)
312-
self.assertEqual(len(non_squashed['RootFS']['Layers']), 4)
313-
self.assertEqual(len(squashed['RootFS']['Layers']), 2)
311+
assert len(non_squashed['RootFS']['Layers']) == 4
312+
assert len(squashed['RootFS']['Layers']) == 2
314313

315314
def test_build_stderr_data(self):
316315
control_chars = ['\x1b[91m', '\x1b[0m']
@@ -329,7 +328,7 @@ def test_build_stderr_data(self):
329328
expected = '{0}{2}\n{1}'.format(
330329
control_chars[0], control_chars[1], snippet
331330
)
332-
self.assertTrue(any([line == expected for line in lines]))
331+
assert any([line == expected for line in lines])
333332

334333
def test_build_gzip_encoding(self):
335334
base_dir = tempfile.mkdtemp()
@@ -375,7 +374,7 @@ def test_build_with_dockerfile_empty_lines(self):
375374
assert 'Successfully built' in lines[-1]['stream']
376375

377376
def test_build_gzip_custom_encoding(self):
378-
with self.assertRaises(errors.DockerException):
377+
with pytest.raises(errors.DockerException):
379378
self.client.build(path='.', gzip=True, encoding='text/html')
380379

381380
@requires_api_version('1.32')

tests/integration/api_client_test.py

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
class InformationTest(BaseAPIIntegrationTest):
1515
def test_version(self):
1616
res = self.client.version()
17-
self.assertIn('GoVersion', res)
18-
self.assertIn('Version', res)
17+
assert 'GoVersion' in res
18+
assert 'Version' in res
1919

2020
def test_info(self):
2121
res = self.client.info()
22-
self.assertIn('Containers', res)
23-
self.assertIn('Images', res)
24-
self.assertIn('Debug', res)
22+
assert 'Containers' in res
23+
assert 'Images' in res
24+
assert 'Debug' in res
2525

2626

2727
class LoadConfigTest(BaseAPIIntegrationTest):
@@ -35,12 +35,12 @@ def test_load_legacy_config(self):
3535
f.write('email = [email protected]')
3636
f.close()
3737
cfg = docker.auth.load_config(cfg_path)
38-
self.assertNotEqual(cfg[docker.auth.INDEX_NAME], None)
38+
assert cfg[docker.auth.INDEX_NAME] is not None
3939
cfg = cfg[docker.auth.INDEX_NAME]
40-
self.assertEqual(cfg['username'], 'sakuya')
41-
self.assertEqual(cfg['password'], 'izayoi')
42-
self.assertEqual(cfg['email'], '[email protected]')
43-
self.assertEqual(cfg.get('Auth'), None)
40+
assert cfg['username'] == 'sakuya'
41+
assert cfg['password'] == 'izayoi'
42+
assert cfg['email'] == '[email protected]'
43+
assert cfg.get('Auth') is None
4444

4545
def test_load_json_config(self):
4646
folder = tempfile.mkdtemp()
@@ -53,22 +53,22 @@ def test_load_json_config(self):
5353
docker.auth.INDEX_URL, auth_, email_))
5454
f.close()
5555
cfg = docker.auth.load_config(cfg_path)
56-
self.assertNotEqual(cfg[docker.auth.INDEX_URL], None)
56+
assert cfg[docker.auth.INDEX_URL] is not None
5757
cfg = cfg[docker.auth.INDEX_URL]
58-
self.assertEqual(cfg['username'], 'sakuya')
59-
self.assertEqual(cfg['password'], 'izayoi')
60-
self.assertEqual(cfg['email'], '[email protected]')
61-
self.assertEqual(cfg.get('Auth'), None)
58+
assert cfg['username'] == 'sakuya'
59+
assert cfg['password'] == 'izayoi'
60+
assert cfg['email'] == '[email protected]'
61+
assert cfg.get('Auth') is None
6262

6363

6464
class AutoDetectVersionTest(unittest.TestCase):
6565
def test_client_init(self):
6666
client = docker.APIClient(version='auto', **kwargs_from_env())
6767
client_version = client._version
6868
api_version = client.version(api_version=False)['ApiVersion']
69-
self.assertEqual(client_version, api_version)
69+
assert client_version == api_version
7070
api_version_2 = client.version()['ApiVersion']
71-
self.assertEqual(client_version, api_version_2)
71+
assert client_version == api_version_2
7272
client.close()
7373

7474

@@ -90,8 +90,8 @@ def test_timeout(self):
9090
except:
9191
pass
9292
end = time.time()
93-
self.assertTrue(res is None)
94-
self.assertTrue(end - start < 2 * self.timeout)
93+
assert res is None
94+
assert end - start < 2 * self.timeout
9595

9696

9797
class UnixconnTest(unittest.TestCase):
@@ -112,5 +112,6 @@ def test_resource_warnings(self):
112112
client.close()
113113
del client
114114

115-
assert len(w) == 0, \
116-
"No warnings produced: {0}".format(w[0].message)
115+
assert len(w) == 0, "No warnings produced: {0}".format(
116+
w[0].message
117+
)

0 commit comments

Comments
 (0)