Skip to content

Commit aadbed6

Browse files
frgfmfmassa
authored andcommitted
test: Updated asserts in test_utils (#1499)
* test: Updated asserts in test_utils Updated all raw asserts to corresponding unittest.TestCase.assert. See #1483 * style: Fixed lint check
1 parent 5eee011 commit aadbed6

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

test/test_utils.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ def test_make_grid_not_inplace(self):
1616
t_clone = t.clone()
1717

1818
utils.make_grid(t, normalize=False)
19-
assert torch.equal(t, t_clone), 'make_grid modified tensor in-place'
19+
self.assertTrue(torch.equal(t, t_clone), 'make_grid modified tensor in-place')
2020

2121
utils.make_grid(t, normalize=True, scale_each=False)
22-
assert torch.equal(t, t_clone), 'make_grid modified tensor in-place'
22+
self.assertTrue(torch.equal(t, t_clone), 'make_grid modified tensor in-place')
2323

2424
utils.make_grid(t, normalize=True, scale_each=True)
25-
assert torch.equal(t, t_clone), 'make_grid modified tensor in-place'
25+
self.assertTrue(torch.equal(t, t_clone), 'make_grid modified tensor in-place')
2626

2727
def test_normalize_in_make_grid(self):
2828
t = torch.rand(5, 3, 10, 10) * 255
@@ -38,22 +38,22 @@ def test_normalize_in_make_grid(self):
3838
rounded_grid_max = torch.round(grid_max * 10 ** n_digits) / (10 ** n_digits)
3939
rounded_grid_min = torch.round(grid_min * 10 ** n_digits) / (10 ** n_digits)
4040

41-
assert torch.equal(norm_max, rounded_grid_max), 'Normalized max is not equal to 1'
42-
assert torch.equal(norm_min, rounded_grid_min), 'Normalized min is not equal to 0'
41+
self.assertTrue(torch.equal(norm_max, rounded_grid_max), 'Normalized max is not equal to 1')
42+
self.assertTrue(torch.equal(norm_min, rounded_grid_min), 'Normalized min is not equal to 0')
4343

4444
@unittest.skipIf('win' in sys.platform, 'temporarily disabled on Windows')
4545
def test_save_image(self):
4646
with tempfile.NamedTemporaryFile(suffix='.png') as f:
4747
t = torch.rand(2, 3, 64, 64)
4848
utils.save_image(t, f.name)
49-
assert os.path.exists(f.name), 'The image is not present after save'
49+
self.assertTrue(os.path.exists(f.name), 'The image is not present after save')
5050

5151
@unittest.skipIf('win' in sys.platform, 'temporarily disabled on Windows')
5252
def test_save_image_single_pixel(self):
5353
with tempfile.NamedTemporaryFile(suffix='.png') as f:
5454
t = torch.rand(1, 3, 1, 1)
5555
utils.save_image(t, f.name)
56-
assert os.path.exists(f.name), 'The pixel image is not present after save'
56+
self.assertTrue(os.path.exists(f.name), 'The pixel image is not present after save')
5757

5858
@unittest.skipIf('win' in sys.platform, 'temporarily disabled on Windows')
5959
def test_save_image_file_object(self):
@@ -64,7 +64,8 @@ def test_save_image_file_object(self):
6464
fp = BytesIO()
6565
utils.save_image(t, fp, format='png')
6666
img_bytes = Image.open(fp)
67-
assert torch.equal(F.to_tensor(img_orig), F.to_tensor(img_bytes)), 'Image not stored in file object'
67+
self.assertTrue(torch.equal(F.to_tensor(img_orig), F.to_tensor(img_bytes)),
68+
'Image not stored in file object')
6869

6970
@unittest.skipIf('win' in sys.platform, 'temporarily disabled on Windows')
7071
def test_save_image_single_pixel_file_object(self):
@@ -75,7 +76,8 @@ def test_save_image_single_pixel_file_object(self):
7576
fp = BytesIO()
7677
utils.save_image(t, fp, format='png')
7778
img_bytes = Image.open(fp)
78-
assert torch.equal(F.to_tensor(img_orig), F.to_tensor(img_bytes)), 'Pixel Image not stored in file object'
79+
self.assertTrue(torch.equal(F.to_tensor(img_orig), F.to_tensor(img_bytes)),
80+
'Pixel Image not stored in file object')
7981

8082

8183
if __name__ == '__main__':

0 commit comments

Comments
 (0)