From df0c3776c29d6cc6effd9bcec68fd06d7abde4b7 Mon Sep 17 00:00:00 2001 From: Michał Górny Date: Sun, 29 Oct 2017 17:01:42 +0100 Subject: testutil: Simplify tests to use shutil.rmtree() for tempdir --- tests/test_find_top_level.py | 18 ----------------- tests/test_recursiveloader.py | 46 ++++--------------------------------------- tests/testutil.py | 7 ++----- 3 files changed, 6 insertions(+), 65 deletions(-) diff --git a/tests/test_find_top_level.py b/tests/test_find_top_level.py index deaee9c..2218799 100644 --- a/tests/test_find_top_level.py +++ b/tests/test_find_top_level.py @@ -164,10 +164,6 @@ class TestCrossDevice(TempDirTestCase): super(TestCrossDevice, self).setUp() os.symlink('/proc', os.path.join(self.dir, 'test')) - def tearDown(self): - os.unlink(os.path.join(self.dir, 'test')) - super(TestCrossDevice, self).tearDown() - def test_find_top_level_manifest(self): self.assertIsNone( gemato.find_top_level.find_top_level_manifest( @@ -188,10 +184,6 @@ class TestCrossDeviceManifest(TempDirTestCase): super(TestCrossDeviceManifest, self).setUp() os.symlink('/proc/version', os.path.join(self.dir, 'Manifest')) - def tearDown(self): - os.unlink(os.path.join(self.dir, 'Manifest')) - super(TestCrossDeviceManifest, self).tearDown() - def test_find_top_level_manifest(self): self.assertIsNone( gemato.find_top_level.find_top_level_manifest( @@ -215,11 +207,6 @@ class TestCompressedManifest(TempDirTestCase): with gzip.GzipFile(os.path.join(self.dir, 'subc/sub/Manifest.gz'), 'wb'): pass - def tearDown(self): - os.unlink(os.path.join(self.dir, 'subc/sub/Manifest.gz')) - os.unlink(os.path.join(self.dir, 'Manifest.gz')) - super(TestCompressedManifest, self).tearDown() - def test_find_top_level_manifest(self): self.assertEqual( os.path.relpath( @@ -266,11 +253,6 @@ class TestCompressedManifestWithIgnore(TempDirTestCase): with gzip.GzipFile(os.path.join(self.dir, 'subc/sub/Manifest.gz'), 'wb'): pass - def tearDown(self): - os.unlink(os.path.join(self.dir, 'subc/sub/Manifest.gz')) - os.unlink(os.path.join(self.dir, 'Manifest.gz')) - super(TestCompressedManifestWithIgnore, self).tearDown() - def test_find_top_level_manifest(self): self.assertEqual( os.path.relpath( diff --git a/tests/test_recursiveloader.py b/tests/test_recursiveloader.py index 68ed602..2b8fef9 100644 --- a/tests/test_recursiveloader.py +++ b/tests/test_recursiveloader.py @@ -1579,10 +1579,6 @@ DATA sub/version 0 MD5 d41d8cd98f00b204e9800998ecf8427e super(CrossDeviceManifestTest, self).setUp() os.symlink('/proc', os.path.join(self.dir, 'sub')) - def tearDown(self): - os.unlink(os.path.join(self.dir, 'sub')) - super(CrossDeviceManifestTest, self).tearDown() - def test_assert_directory_verifies(self): m = gemato.recursiveloader.ManifestRecursiveLoader( os.path.join(self.dir, 'Manifest')) @@ -1635,10 +1631,6 @@ class CrossDeviceEmptyManifestTest(TempDirTestCase): super(CrossDeviceEmptyManifestTest, self).setUp() os.symlink('/proc', os.path.join(self.dir, 'sub')) - def tearDown(self): - os.unlink(os.path.join(self.dir, 'sub')) - super(CrossDeviceEmptyManifestTest, self).tearDown() - def test_assert_directory_verifies(self): m = gemato.recursiveloader.ManifestRecursiveLoader( os.path.join(self.dir, 'Manifest')) @@ -1693,10 +1685,6 @@ IGNORE sub super(CrossDeviceIgnoreManifestTest, self).setUp() os.symlink('/proc', os.path.join(self.dir, 'sub')) - def tearDown(self): - os.unlink(os.path.join(self.dir, 'sub')) - super(CrossDeviceIgnoreManifestTest, self).tearDown() - def test_assert_directory_verifies(self): m = gemato.recursiveloader.ManifestRecursiveLoader( os.path.join(self.dir, 'Manifest')) @@ -1808,6 +1796,10 @@ class UnreadableDirectoryTest(TempDirTestCase): super(UnreadableDirectoryTest, self).setUp() os.chmod(os.path.join(self.dir, 'test'), 0) + def tearDown(self): + os.chmod(os.path.join(self.dir, 'test'), 0o555) + super(UnreadableDirectoryTest, self).tearDown() + def test_assert_directory_verifies(self): m = gemato.recursiveloader.ManifestRecursiveLoader( os.path.join(self.dir, 'Manifest')) @@ -1838,10 +1830,6 @@ DATA test 0 MD5 d41d8cd98f00b204e9800998ecf8427e with gzip.GzipFile(self.manifest_gz, 'wb') as f: f.write(self.MANIFEST) - def tearDown(self): - os.unlink(self.manifest_gz) - super(CompressedTopManifestTest, self).tearDown() - def test_find_path_entry(self): m = gemato.recursiveloader.ManifestRecursiveLoader( self.manifest_gz) @@ -1906,10 +1894,6 @@ MANIFEST sub/Manifest.gz 78 MD5 9c158f87b2445279d7c8aac439612fba with io.open(self.manifest_gz, 'wb') as f: f.write(base64.b64decode(self.SUB_MANIFEST)) - def tearDown(self): - os.unlink(self.manifest_gz) - super(CompressedSubManifestTest, self).tearDown() - def test_find_path_entry(self): m = gemato.recursiveloader.ManifestRecursiveLoader( os.path.join(self.dir, 'Manifest')) @@ -1964,10 +1948,6 @@ MANIFEST a/Manifest 0 MD5 d41d8cd98f00b204e9800998ecf8427e with gzip.GzipFile(self.manifest_gz, 'wb') as f: f.write(self.MANIFEST) - def tearDown(self): - os.unlink(self.manifest_gz) - super(CompressedManifestOrderingTest, self).tearDown() - def test__iter_manifests_for_path_order(self): m = gemato.recursiveloader.ManifestRecursiveLoader( self.manifest_gz) @@ -2089,10 +2069,6 @@ DATA test 0 MD5 d41d8cd98f00b204e9800998ecf8427e os.path.join(self.dir, 'sub/Manifest.gz'), 'wb') as f: f.write(self.SUB_MANIFEST) - def tearDown(self): - os.unlink(self.manifest_gz) - super(UnregisteredCompressedManifestTestCase, self).tearDown() - def test_load_manifests(self): m = gemato.recursiveloader.ManifestRecursiveLoader( os.path.join(self.dir, 'Manifest')) @@ -2188,13 +2164,6 @@ class CreateNewManifestTest(TempDirTestCase): super(CreateNewManifestTest, self).setUp() self.path = os.path.join(self.dir, 'Manifest') - def tearDown(self): - try: - os.unlink(self.path) - except OSError: - pass - super(CreateNewManifestTest, self).tearDown() - def test_load_without_create(self): self.assertRaises(IOError, gemato.recursiveloader.ManifestRecursiveLoader, @@ -2252,13 +2221,6 @@ class CreateNewCompressedManifestTest(TempDirTestCase): super(CreateNewCompressedManifestTest, self).setUp() self.path = os.path.join(self.dir, 'Manifest.gz') - def tearDown(self): - try: - os.unlink(self.path) - except OSError: - pass - super(CreateNewCompressedManifestTest, self).tearDown() - def test_load_without_create(self): self.assertRaises(IOError, gemato.recursiveloader.ManifestRecursiveLoader, diff --git a/tests/testutil.py b/tests/testutil.py index 2a002c1..9e294a5 100644 --- a/tests/testutil.py +++ b/tests/testutil.py @@ -7,6 +7,7 @@ import io import logging import os import os.path +import shutil import sys import tempfile import unittest @@ -40,9 +41,5 @@ class TempDirTestCase(LoggingTestCase): f.write(v) def tearDown(self): - for k in self.FILES: - os.unlink(os.path.join(self.dir, k)) - for k in reversed(self.DIRS): - os.rmdir(os.path.join(self.dir, k)) - os.rmdir(self.dir) + shutil.rmtree(self.dir) super(TempDirTestCase, self).tearDown() -- cgit v1.2.3