Skip to content

Commit

Permalink
refactor(test feedstock io): remove unittest
Browse files Browse the repository at this point in the history
  • Loading branch information
hulkoba committed Jul 2, 2024
1 parent a8b2040 commit 5415f50
Showing 1 changed file with 25 additions and 42 deletions.
67 changes: 25 additions & 42 deletions tests/test_feedstock_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import string
import shutil
import tempfile
import unittest

import git
from git.index.typ import BlobFilter
Expand Down Expand Up @@ -47,7 +46,7 @@ def parameterize():
shutil.rmtree(tmp_dir)


class TestFeedstockIO(unittest.TestCase):
class TestFeedstockIO():
def setUp(self):
self.old_dir = os.getcwd()

Expand All @@ -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(
Expand Down Expand Up @@ -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():
Expand All @@ -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():
Expand All @@ -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():
Expand All @@ -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():
Expand All @@ -195,41 +186,33 @@ 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)
del self.old_dir

shutil.rmtree(self.tmp_dir)
del self.tmp_dir


if __name__ == "__main__":
unittest.main()

0 comments on commit 5415f50

Please sign in to comment.