forked from LBRYCommunity/lbry-sdk
Changed the tests to execute against a real file system instead of a fake one.
This commit is contained in:
parent
e55f9dd21e
commit
25092f56be
1 changed files with 23 additions and 22 deletions
|
@ -7,7 +7,6 @@ import pathlib
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
from pyfakefs.fake_filesystem_unittest import TestCase as FakeFSTestCase
|
|
||||||
from types import SimpleNamespace
|
from types import SimpleNamespace
|
||||||
from contextlib import asynccontextmanager
|
from contextlib import asynccontextmanager
|
||||||
|
|
||||||
|
@ -206,24 +205,24 @@ class DaemonDocsTests(TestCase):
|
||||||
self.fail("\n" + "\n".join(failures))
|
self.fail("\n" + "\n".join(failures))
|
||||||
|
|
||||||
|
|
||||||
class EnsureDirectoryExistsTests(FakeFSTestCase):
|
class EnsureDirectoryExistsTests(TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
self.setUpPyfakefs()
|
|
||||||
|
|
||||||
def test_when_parent_dir_does_not_exist_then_dir_is_created_with_parent(self):
|
def test_when_parent_dir_does_not_exist_then_dir_is_created_with_parent(self):
|
||||||
dir_path = os.path.join("parent_dir", "dir")
|
with tempfile.TemporaryDirectory() as temp_dir:
|
||||||
|
dir_path = os.path.join(temp_dir, "parent_dir", "dir")
|
||||||
ensure_directory_exists(dir_path)
|
ensure_directory_exists(dir_path)
|
||||||
self.assertTrue(os.path.exists(dir_path))
|
self.assertTrue(os.path.exists(dir_path))
|
||||||
|
|
||||||
def test_when_non_writable_dir_exists_then_raise(self):
|
def test_when_non_writable_dir_exists_then_raise(self):
|
||||||
dir_path = "dir"
|
with tempfile.TemporaryDirectory() as temp_dir:
|
||||||
|
dir_path = os.path.join(temp_dir, "dir")
|
||||||
pathlib.Path(dir_path).mkdir(mode=0o555) # creates a non-writable, readable and executable dir
|
pathlib.Path(dir_path).mkdir(mode=0o555) # creates a non-writable, readable and executable dir
|
||||||
with self.assertRaises(PermissionError):
|
with self.assertRaises(PermissionError):
|
||||||
ensure_directory_exists(dir_path)
|
ensure_directory_exists(dir_path)
|
||||||
|
|
||||||
def test_when_dir_exists_and_writable_then_no_raise(self):
|
def test_when_dir_exists_and_writable_then_no_raise(self):
|
||||||
dir_path = "dir"
|
with tempfile.TemporaryDirectory() as temp_dir:
|
||||||
|
dir_path = os.path.join(temp_dir, "dir")
|
||||||
pathlib.Path(dir_path).mkdir(mode=0o777) # creates a writable, readable and executable dir
|
pathlib.Path(dir_path).mkdir(mode=0o777) # creates a writable, readable and executable dir
|
||||||
try:
|
try:
|
||||||
ensure_directory_exists(dir_path)
|
ensure_directory_exists(dir_path)
|
||||||
|
@ -231,7 +230,9 @@ class EnsureDirectoryExistsTests(FakeFSTestCase):
|
||||||
self.fail(f"{type(err).__name__} was raised")
|
self.fail(f"{type(err).__name__} was raised")
|
||||||
|
|
||||||
def test_when_non_dir_file_exists_at_path_then_raise(self):
|
def test_when_non_dir_file_exists_at_path_then_raise(self):
|
||||||
file_path = "file.extension"
|
with tempfile.TemporaryDirectory() as temp_dir:
|
||||||
self.fs.create_file(file_path)
|
file_path = os.path.join(temp_dir, "file.extension")
|
||||||
|
with open(file_path, 'x'):
|
||||||
|
pass
|
||||||
with self.assertRaises(FileExistsError):
|
with self.assertRaises(FileExistsError):
|
||||||
ensure_directory_exists(file_path)
|
ensure_directory_exists(file_path)
|
||||||
|
|
Loading…
Reference in a new issue