diff options
author | Zac Medico <zmedico@gentoo.org> | 2019-11-06 00:03:36 -0800 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2019-11-06 12:05:27 -0800 |
commit | 7b8f57335c43054fe4008b7401d6ac2b3f710c1a (patch) | |
tree | afd788a01ae00478a82d67e66e4b45f227867512 /lib/portage/tests/util | |
parent | emirrordist: _make_layout_links msg UnboundLocalError (diff) | |
download | portage-7b8f57335c43054fe4008b7401d6ac2b3f710c1a.tar.gz portage-7b8f57335c43054fe4008b7401d6ac2b3f710c1a.tar.bz2 portage-7b8f57335c43054fe4008b7401d6ac2b3f710c1a.zip |
FileCopier: capture exceptions
Use ForkExecutor to capture exceptions instead of showing
a full traceback. FileCopier callers will now be responsible
for displaying relevant exception messages.
Bug: https://bugs.gentoo.org/699400
Signed-off-by: Zac Medico <zmedico@gentoo.org>
Diffstat (limited to 'lib/portage/tests/util')
-rw-r--r-- | lib/portage/tests/util/test_file_copier.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/portage/tests/util/test_file_copier.py b/lib/portage/tests/util/test_file_copier.py new file mode 100644 index 000000000..01dfba494 --- /dev/null +++ b/lib/portage/tests/util/test_file_copier.py @@ -0,0 +1,44 @@ +# Copyright 2019 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +import errno +import os +import shutil +import tempfile + +from portage.tests import TestCase +from portage.util._async.FileCopier import FileCopier +from portage.util._eventloop.global_event_loop import global_event_loop + + +class FileCopierTestCase(TestCase): + + def testFileCopier(self): + loop = global_event_loop() + tempdir = tempfile.mkdtemp() + try: + + # regular successful copy + src_path = os.path.join(tempdir, 'src') + dest_path = os.path.join(tempdir, 'dest') + content = b'foo' + with open(src_path, 'wb') as f: + f.write(content) + copier = FileCopier(src_path=src_path, dest_path=dest_path, scheduler=loop) + copier.start() + loop.run_until_complete(copier.async_wait()) + self.assertEqual(copier.returncode, 0) + copier.future.result() + with open(dest_path, 'rb') as f: + self.assertEqual(f.read(), content) + + # failure due to nonexistent src_path + src_path = os.path.join(tempdir, 'does-not-exist') + copier = FileCopier(src_path=src_path, dest_path=dest_path, scheduler=loop) + copier.start() + loop.run_until_complete(copier.async_wait()) + self.assertEqual(copier.returncode, 1) + self.assertEqual(copier.future.exception().errno, errno.ENOENT) + self.assertEqual(copier.future.exception().filename, src_path.encode('utf8')) + finally: + shutil.rmtree(tempdir) |