From 5415f501e91b658cc72092dcd712e23c8319998d Mon Sep 17 00:00:00 2001 From: hulkoba Date: Tue, 2 Jul 2024 13:38:26 +0200 Subject: [PATCH] refactor(test feedstock io): remove unittest --- tests/test_feedstock_io.py | 67 ++++++++++++++------------------------ 1 file changed, 25 insertions(+), 42 deletions(-) diff --git a/tests/test_feedstock_io.py b/tests/test_feedstock_io.py index 4665fbc1e..ba6d94c53 100644 --- a/tests/test_feedstock_io.py +++ b/tests/test_feedstock_io.py @@ -7,7 +7,6 @@ import string import shutil import tempfile -import unittest import git from git.index.typ import BlobFilter @@ -47,7 +46,7 @@ def parameterize(): shutil.rmtree(tmp_dir) -class TestFeedstockIO(unittest.TestCase): +class TestFeedstockIO(): def setUp(self): self.old_dir = os.getcwd() @@ -62,11 +61,9 @@ def setUp(self): def test_repo(self): for tmp_dir, repo, pathfunc in parameterize(): if repo is None: - self.assertTrue(fio.get_repo(pathfunc(tmp_dir)) is None) + assert fio.get_repo(pathfunc(tmp_dir)) is None else: - self.assertIsInstance( - fio.get_repo(pathfunc(tmp_dir)), git.Repo - ) + assert isinstance(fio.get_repo(pathfunc(tmp_dir)), git.Repo) possible_repo_subdir = os.path.join( tmp_dir, "".join( @@ -97,12 +94,10 @@ def test_set_exe_file(self): fio.set_exe_file(pathfunc(filename), set_exe) file_mode = os.stat(filename).st_mode - self.assertEqual(file_mode & set_mode, int(set_exe) * set_mode) + assert file_mode & set_mode == int(set_exe) * set_mode if repo is not None: blob = next(repo.index.iter_blobs(BlobFilter(filename)))[1] - self.assertEqual( - blob.mode & set_mode, int(set_exe) * set_mode - ) + assert blob.mode & set_mode == int(set_exe) * set_mode def test_write_file(self): for tmp_dir, repo, pathfunc in parameterize(): @@ -120,13 +115,13 @@ def test_write_file(self): with io.open(filename, "r", encoding="utf-8") as fh: read_text = fh.read() - self.assertEqual(write_text, read_text) + assert write_text == read_text if repo is not None: blob = next(repo.index.iter_blobs(BlobFilter(filename)))[1] read_text = blob.data_stream[3].read().decode("utf-8") - self.assertEqual(write_text, read_text) + assert write_text == read_text def test_touch_file(self): for tmp_dir, repo, pathfunc in parameterize(): @@ -139,13 +134,13 @@ def test_touch_file(self): with io.open(filename, "r", encoding="utf-8") as fh: read_text = fh.read() - self.assertEqual("", read_text) + assert "" == read_text if repo is not None: blob = next(repo.index.iter_blobs(BlobFilter(filename)))[1] read_text = blob.data_stream[3].read().decode("utf-8") - self.assertEqual("", read_text) + assert "" == read_text def test_remove_file(self): for tmp_dir, repo, pathfunc in parameterize(): @@ -163,25 +158,21 @@ def test_remove_file(self): if repo is not None: repo.index.add([filename]) - self.assertTrue(os.path.exists(filename)) + assert os.path.exists(filename) if dirname: - self.assertTrue(os.path.exists(dirname)) - self.assertTrue(os.path.exists(os.path.dirname(dirname))) + assert os.path.exists(dirname) + assert os.path.exists(os.path.dirname(dirname)) if repo is not None: - self.assertTrue( - list(repo.index.iter_blobs(BlobFilter(filename))) - ) + assert list(repo.index.iter_blobs(BlobFilter(filename))) fio.remove_file(pathfunc(filename)) - self.assertFalse(os.path.exists(filename)) + assert not os.path.exists(filename) if dirname: - self.assertFalse(os.path.exists(dirname)) - self.assertFalse(os.path.exists(os.path.dirname(dirname))) + assert not os.path.exists(dirname) + assert not os.path.exists(os.path.dirname(dirname)) if repo is not None: - self.assertFalse( - list(repo.index.iter_blobs(BlobFilter(filename))) - ) + assert not list(repo.index.iter_blobs(BlobFilter(filename))) def test_copy_file(self): for tmp_dir, repo, pathfunc in parameterize(): @@ -195,33 +186,29 @@ def test_copy_file(self): with io.open(filename1, "w", encoding="utf-8", newline="\n") as fh: fh.write(write_text) - self.assertTrue(os.path.exists(filename1)) - self.assertFalse(os.path.exists(filename2)) + assert os.path.exists(filename1) + assert not os.path.exists(filename2) if repo is not None: - self.assertFalse( - list(repo.index.iter_blobs(BlobFilter(filename2))) - ) + assert not list(repo.index.iter_blobs(BlobFilter(filename2))) fio.copy_file(pathfunc(filename1), pathfunc(filename2)) - self.assertTrue(os.path.exists(filename1)) - self.assertTrue(os.path.exists(filename2)) + assert os.path.exists(filename1) + assert os.path.exists(filename2) if repo is not None: - self.assertTrue( - list(repo.index.iter_blobs(BlobFilter(filename2))) - ) + assert list(repo.index.iter_blobs(BlobFilter(filename2))) read_text = "" with io.open(filename2, "r", encoding="utf-8") as fh: read_text = fh.read() - self.assertEqual(write_text, read_text) + assert write_text == read_text if repo is not None: blob = next(repo.index.iter_blobs(BlobFilter(filename2)))[1] read_text = blob.data_stream[3].read().decode("utf-8") - self.assertEqual(write_text, read_text) + assert write_text == read_text def tearDown(self): os.chdir(self.old_dir) @@ -229,7 +216,3 @@ def tearDown(self): shutil.rmtree(self.tmp_dir) del self.tmp_dir - - -if __name__ == "__main__": - unittest.main()