mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Use tmp dir for test output
`shutil.rmtree` would fail in `TestUtils.test_clean_output_dir` on some filesystems if an application with a filewatcher had the pelican project open while the test ran. Using `tempfile.mkdtmp` for test directories circumvents this.
This commit is contained in:
parent
2a7e691000
commit
27f2c678cb
1 changed files with 11 additions and 3 deletions
|
|
@ -20,6 +20,14 @@ from pelican.writers import Writer
|
||||||
class TestUtils(LoggedTestCase):
|
class TestUtils(LoggedTestCase):
|
||||||
_new_attribute = 'new_value'
|
_new_attribute = 'new_value'
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super().setUp()
|
||||||
|
self.temp_output = mkdtemp(prefix='pelicantests.')
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
super().tearDown()
|
||||||
|
shutil.rmtree(self.temp_output)
|
||||||
|
|
||||||
@utils.deprecated_attribute(
|
@utils.deprecated_attribute(
|
||||||
old='_old_attribute', new='_new_attribute',
|
old='_old_attribute', new='_new_attribute',
|
||||||
since=(3, 1, 0), remove=(4, 1, 3))
|
since=(3, 1, 0), remove=(4, 1, 3))
|
||||||
|
|
@ -468,7 +476,7 @@ class TestUtils(LoggedTestCase):
|
||||||
|
|
||||||
def test_clean_output_dir(self):
|
def test_clean_output_dir(self):
|
||||||
retention = ()
|
retention = ()
|
||||||
test_directory = os.path.join(os.path.dirname(__file__),
|
test_directory = os.path.join(self.temp_output,
|
||||||
'clean_output')
|
'clean_output')
|
||||||
content = os.path.join(os.path.dirname(__file__), 'content')
|
content = os.path.join(os.path.dirname(__file__), 'content')
|
||||||
shutil.copytree(content, test_directory)
|
shutil.copytree(content, test_directory)
|
||||||
|
|
@ -479,14 +487,14 @@ class TestUtils(LoggedTestCase):
|
||||||
|
|
||||||
def test_clean_output_dir_not_there(self):
|
def test_clean_output_dir_not_there(self):
|
||||||
retention = ()
|
retention = ()
|
||||||
test_directory = os.path.join(os.path.dirname(__file__),
|
test_directory = os.path.join(self.temp_output,
|
||||||
'does_not_exist')
|
'does_not_exist')
|
||||||
utils.clean_output_dir(test_directory, retention)
|
utils.clean_output_dir(test_directory, retention)
|
||||||
self.assertFalse(os.path.exists(test_directory))
|
self.assertFalse(os.path.exists(test_directory))
|
||||||
|
|
||||||
def test_clean_output_dir_is_file(self):
|
def test_clean_output_dir_is_file(self):
|
||||||
retention = ()
|
retention = ()
|
||||||
test_directory = os.path.join(os.path.dirname(__file__),
|
test_directory = os.path.join(self.temp_output,
|
||||||
'this_is_a_file')
|
'this_is_a_file')
|
||||||
f = open(test_directory, 'w')
|
f = open(test_directory, 'w')
|
||||||
f.write('')
|
f.write('')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue