From: Markus Lehtonen Date: Wed, 9 Oct 2013 11:38:52 +0000 (+0300) Subject: tests: make sure to restore dir permissions X-Git-Tag: submit/devel/20190730.075437~74 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b40ae8078f73e2e47ba0a4f4b32bbb4593dcf86b;p=services%2Fobs-service-git-buildpackage.git tests: make sure to restore dir permissions So that tests don't leave stale temporary directories in case of tests fail. Change-Id: I06aa23b2ec6805b18a3c597101ab186b8aa24abc Signed-off-by: Markus Lehtonen --- diff --git a/tests/test_gbp_repocache.py b/tests/test_gbp_repocache.py index 2f04cbd..7403bde 100644 --- a/tests/test_gbp_repocache.py +++ b/tests/test_gbp_repocache.py @@ -161,27 +161,34 @@ class TestCachedRepo(UnitTestsBase): def test_cache_access_error(self): """Test cached directory with invalid permissions""" + s_rwx = stat.S_IREAD | stat.S_IWRITE | stat.S_IEXEC + # Check base cachedir creation access error os.chmod(self.workdir, 0) with assert_raises(CachedRepoError): - repo = self.MockCachedRepo(self.orig_repo.path) - os.chmod(self.workdir, stat.S_IREAD | stat.S_IWRITE | stat.S_IEXEC) + try: + repo = self.MockCachedRepo(self.orig_repo.path) + finally: + os.chmod(self.workdir, s_rwx) repo = self.MockCachedRepo(self.orig_repo.path) del repo # Check cache base dir access error os.chmod(self.cachedir, 0) with assert_raises(CachedRepoError): - repo = self.MockCachedRepo(self.orig_repo.path) - os.chmod(self.cachedir, stat.S_IREAD | stat.S_IWRITE | stat.S_IEXEC) + try: + repo = self.MockCachedRepo(self.orig_repo.path) + finally: + os.chmod(self.cachedir, s_rwx) repo = self.MockCachedRepo(self.orig_repo.path) del repo # Check repodir delete error os.chmod(self.cachedir, stat.S_IREAD | stat.S_IEXEC) with assert_raises(CachedRepoError): - # Change repo type -> tries to delete - repo = self.MockCachedRepo(self.orig_repo.path, bare=True) - os.chmod(self.cachedir, stat.S_IREAD | stat.S_IWRITE | stat.S_IEXEC) - + try: + # Change repo type -> tries to delete + repo = self.MockCachedRepo(self.orig_repo.path, bare=True) + finally: + os.chmod(self.cachedir, s_rwx)