diff options
author | Jesús <heckyel@hyperbola.info> | 2022-04-10 07:57:14 +0800 |
---|---|---|
committer | Jesús <heckyel@hyperbola.info> | 2022-04-10 07:57:14 +0800 |
commit | c8046abd97bae36fa50320c32843cf6141752f93 (patch) | |
tree | 1dd684a1936a08e7d5229dfb99f2d6d7fb604559 /test/test_utils.py | |
parent | 40748dd6d0bb053a1c90bcfe874d3cee4b306744 (diff) | |
parent | ca5300c7edadad46ede0249ad9fa8feaa4ccddd4 (diff) | |
download | hypervideo-pre-c8046abd97bae36fa50320c32843cf6141752f93.tar.lz hypervideo-pre-c8046abd97bae36fa50320c32843cf6141752f93.tar.xz hypervideo-pre-c8046abd97bae36fa50320c32843cf6141752f93.zip |
updated from upstream | 10/04/2022 at 07:57
Diffstat (limited to 'test/test_utils.py')
-rw-r--r-- | test/test_utils.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/test/test_utils.py b/test/test_utils.py index 31f168998..1f826c2f2 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -56,6 +56,7 @@ from yt_dlp.utils import ( is_html, js_to_json, limit_length, + locked_file, merge_dicts, mimetype2ext, month_by_name, @@ -1795,6 +1796,36 @@ Line 1 self.assertEqual(Config.hide_login_info(['--username=foo']), ['--username=PRIVATE']) + def test_locked_file(self): + TEXT = 'test_locked_file\n' + FILE = 'test_locked_file.ytdl' + MODES = 'war' # Order is important + + try: + for lock_mode in MODES: + with locked_file(FILE, lock_mode, False) as f: + if lock_mode == 'r': + self.assertEqual(f.read(), TEXT * 2, 'Wrong file content') + else: + f.write(TEXT) + for test_mode in MODES: + testing_write = test_mode != 'r' + try: + with locked_file(FILE, test_mode, False): + pass + except (BlockingIOError, PermissionError): + if not testing_write: # FIXME + print(f'Known issue: Exclusive lock ({lock_mode}) blocks read access ({test_mode})') + continue + self.assertTrue(testing_write, f'{test_mode} is blocked by {lock_mode}') + else: + self.assertFalse(testing_write, f'{test_mode} is not blocked by {lock_mode}') + finally: + try: + os.remove(FILE) + except Exception: + pass + if __name__ == '__main__': unittest.main() |