diff options
Diffstat (limited to 'pyfakefs/tests/fake_stat_time_test.py')
-rw-r--r-- | pyfakefs/tests/fake_stat_time_test.py | 45 |
1 files changed, 23 insertions, 22 deletions
diff --git a/pyfakefs/tests/fake_stat_time_test.py b/pyfakefs/tests/fake_stat_time_test.py index 866a1a1..5833ebd 100644 --- a/pyfakefs/tests/fake_stat_time_test.py +++ b/pyfakefs/tests/fake_stat_time_test.py @@ -17,21 +17,20 @@ from collections import namedtuple from pyfakefs.tests.test_utils import RealFsTestCase -FileTime = namedtuple('FileTime', 'st_ctime, st_atime, st_mtime') +FileTime = namedtuple("FileTime", "st_ctime, st_atime, st_mtime") class FakeStatTestBase(RealFsTestCase): - def setUp(self): super().setUp() # we disable the tests for MacOS to avoid very long builds due # to the 1s time resolution - we know that the functionality is # similar to Linux self.check_linux_and_windows() - self.file_path = self.make_path('some_file') + self.file_path = self.make_path("some_file") # MacOS has a timestamp resolution of 1 second self.sleep_time = 1.1 if self.is_macos else 0.01 - self.mode = '' + self.mode = "" def stat_time(self, path): stat = self.os.stat(path) @@ -41,9 +40,11 @@ class FakeStatTestBase(RealFsTestCase): else: # calling time.time() advances mocked time time.time() - return FileTime(st_ctime=stat.st_ctime, - st_atime=stat.st_atime, - st_mtime=stat.st_mtime) + return FileTime( + st_ctime=stat.st_ctime, + st_atime=stat.st_atime, + st_mtime=stat.st_mtime, + ) def assertLessExceptWindows(self, time1, time2): if self.is_windows_fs: @@ -68,7 +69,7 @@ class FakeStatTestBase(RealFsTestCase): with self.mock_time(): with self.open(self.file_path, self.mode) as f: created = self.stat_time(self.file_path) - f.write('foo') + f.write("foo") written = self.stat_time(self.file_path) closed = self.stat_time(self.file_path) @@ -92,7 +93,7 @@ class FakeStatTestBase(RealFsTestCase): before = self.stat_time(self.file_path) with self.open(self.file_path, self.mode) as f: opened = self.stat_time(self.file_path) - f.write('foo') + f.write("foo") written = self.stat_time(self.file_path) closed = self.stat_time(self.file_path) @@ -118,7 +119,7 @@ class FakeStatTestBase(RealFsTestCase): before = self.stat_time(self.file_path) with self.open(self.file_path, self.mode) as f: opened = self.stat_time(self.file_path) - f.write('foo') + f.write("foo") written = self.stat_time(self.file_path) f.flush() flushed = self.stat_time(self.file_path) @@ -131,7 +132,7 @@ class FakeStatTestBase(RealFsTestCase): self.create_file(self.file_path) before = self.stat_time(self.file_path) - with self.open(self.file_path, 'r') as f: + with self.open(self.file_path, "r") as f: opened = self.stat_time(self.file_path) f.read() read = self.stat_time(self.file_path) @@ -388,7 +389,7 @@ class FakeStatTestBase(RealFsTestCase): class TestFakeModeW(FakeStatTestBase): def setUp(self): super(TestFakeModeW, self).setUp() - self.mode = 'w' + self.mode = "w" def test_open_close_new_file(self): self.check_open_close_new_file() @@ -409,7 +410,7 @@ class TestFakeModeW(FakeStatTestBase): self.check_open_write_flush_close_w_mode() def test_read_raises(self): - with self.open(self.file_path, 'w') as f: + with self.open(self.file_path, "w") as f: with self.assertRaises(OSError): f.read() @@ -422,7 +423,7 @@ class TestRealModeW(TestFakeModeW): class TestFakeModeWPlus(FakeStatTestBase): def setUp(self): super(TestFakeModeWPlus, self).setUp() - self.mode = 'w+' + self.mode = "w+" def test_open_close_new_file(self): self.check_open_close_new_file() @@ -475,7 +476,7 @@ class TestRealModeWPlus(TestFakeModeWPlus): class TestFakeModeA(FakeStatTestBase): def setUp(self): super(TestFakeModeA, self).setUp() - self.mode = 'a' + self.mode = "a" def test_open_close_new_file(self): self.check_open_close_new_file() @@ -496,7 +497,7 @@ class TestFakeModeA(FakeStatTestBase): self.check_open_write_flush_close_non_w_mode() def test_read_raises(self): - with self.open(self.file_path, 'a') as f: + with self.open(self.file_path, "a") as f: with self.assertRaises(OSError): f.read() @@ -509,7 +510,7 @@ class TestRealModeA(TestFakeModeA): class TestFakeModeAPlus(FakeStatTestBase): def setUp(self): super(TestFakeModeAPlus, self).setUp() - self.mode = 'a+' + self.mode = "a+" def test_open_close_new_file(self): self.check_open_close_new_file() @@ -544,7 +545,7 @@ class TestRealModeAPlus(TestFakeModeAPlus): class TestFakeModeR(FakeStatTestBase): def setUp(self): super(TestFakeModeR, self).setUp() - self.mode = 'r' + self.mode = "r" def test_open_close(self): self.check_open_close_non_w_mode() @@ -579,7 +580,7 @@ class TestFakeModeR(FakeStatTestBase): def test_open_not_existing_raises(self): with self.assertRaises(OSError): - with self.open(self.file_path, 'r'): + with self.open(self.file_path, "r"): pass @@ -591,7 +592,7 @@ class TestRealModeR(TestFakeModeR): class TestFakeModeRPlus(FakeStatTestBase): def setUp(self): super(TestFakeModeRPlus, self).setUp() - self.mode = 'r+' + self.mode = "r+" def test_open_close(self): self.check_open_close_non_w_mode() @@ -610,7 +611,7 @@ class TestFakeModeRPlus(FakeStatTestBase): def test_open_not_existing_raises(self): with self.assertRaises(OSError): - with self.open(self.file_path, 'r+'): + with self.open(self.file_path, "r+"): pass @@ -619,5 +620,5 @@ class TestRealModeRPlus(TestFakeModeRPlus): return True -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() |