diff options
author | Tim Harder <radhermit@gmail.com> | 2021-03-05 02:20:19 -0700 |
---|---|---|
committer | Tim Harder <radhermit@gmail.com> | 2021-03-05 02:23:25 -0700 |
commit | b9a3d980ea375be07ef0edfbe4ad021dc6cd7bc7 (patch) | |
tree | 33eab9541b8ebf4f4ccc4164dcf289b7edeac711 /tests | |
parent | mangle: various changes to simplify testing (diff) | |
download | pkgdev-b9a3d980ea375be07ef0edfbe4ad021dc6cd7bc7.tar.gz pkgdev-b9a3d980ea375be07ef0edfbe4ad021dc6cd7bc7.tar.bz2 pkgdev-b9a3d980ea375be07ef0edfbe4ad021dc6cd7bc7.zip |
tests: add initial Mangler tests
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_mangle.py | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/test_mangle.py b/tests/test_mangle.py new file mode 100644 index 0000000..39dde3f --- /dev/null +++ b/tests/test_mangle.py @@ -0,0 +1,46 @@ +from unittest.mock import patch + +from pkgdev.mangle import Mangler +import pytest +from snakeoil.cli.exceptions import UserException +from snakeoil.fileutils import touch +from snakeoil.osutils import pjoin + + +class TestMangler: + + def test_nonexistent_file(self, repo): + path = pjoin(repo.location, 'nonexistent') + assert list(Mangler(repo, [path])) == [] + + def test_empty_file(self, repo): + path = pjoin(repo.location, 'empty') + touch(path) + assert list(Mangler(repo, [path])) == [] + + def test_nonmangled_file(self, repo): + path = pjoin(repo.location, 'file') + with open(path, 'w') as f: + f.write('# comment\n') + assert list(Mangler(repo, [path])) == [] + + def test_mangled_file(self, repo): + path = pjoin(repo.location, 'file') + with open(path, 'w') as f: + f.write('# comment') + assert list(Mangler(repo, [path])) == [path] + with open(path, 'r') as f: + assert f.read() == '# comment\n' + + def test_iterator_exceptions(self, repo): + """Test parallelized iterator against unhandled exceptions.""" + path = pjoin(repo.location, 'file') + with open(path, 'w') as f: + f.write('# comment\n') + + def _mangle_func(self, data): + raise Exception('func failed') + + with patch('pkgdev.mangle.Mangler._mangle_eof', _mangle_func): + with pytest.raises(UserException, match='Exception: func failed'): + list(Mangler(repo, [path])) |