diff options
author | Arthur Zamarin <arthurzam@gentoo.org> | 2022-12-29 19:51:23 +0200 |
---|---|---|
committer | Arthur Zamarin <arthurzam@gentoo.org> | 2022-12-29 19:51:23 +0200 |
commit | ae7dd4184f63185880738c5133f326fe47c6606a (patch) | |
tree | d6d0e55d9684fef5bca6a9035a37763dca8b8402 /tests/checks/test_repo.py | |
parent | bump snakeoil minimal version (diff) | |
download | pkgcheck-ae7dd4184f63185880738c5133f326fe47c6606a.tar.gz pkgcheck-ae7dd4184f63185880738c5133f326fe47c6606a.tar.bz2 pkgcheck-ae7dd4184f63185880738c5133f326fe47c6606a.zip |
format using black
Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
Diffstat (limited to 'tests/checks/test_repo.py')
-rw-r--r-- | tests/checks/test_repo.py | 85 |
1 files changed, 42 insertions, 43 deletions
diff --git a/tests/checks/test_repo.py b/tests/checks/test_repo.py index cd685a52..4220e055 100644 --- a/tests/checks/test_repo.py +++ b/tests/checks/test_repo.py @@ -17,15 +17,14 @@ class TestRepoDirCheck(misc.Tmpdir, misc.ReportTestCase): check_kls = repo.RepoDirCheck def mk_check(self): - self.repo = FakeRepo(repo_id='repo', location=self.dir) - options = arghparse.Namespace( - target_repo=self.repo, cache={'git': False}, gentoo_repo=True) + self.repo = FakeRepo(repo_id="repo", location=self.dir) + options = arghparse.Namespace(target_repo=self.repo, cache={"git": False}, gentoo_repo=True) git_addon = addons.git.GitAddon(options) return repo.RepoDirCheck(options, git_addon=git_addon) def mk_pkg(self, cpvstr): pkg = atom.atom(cpvstr) - filesdir = pjoin(self.repo.location, pkg.category, pkg.package, 'files') + filesdir = pjoin(self.repo.location, pkg.category, pkg.package, "files") os.makedirs(filesdir, exist_ok=True) return filesdir @@ -34,100 +33,100 @@ class TestRepoDirCheck(misc.Tmpdir, misc.ReportTestCase): def test_empty_file(self): check = self.mk_check() - bin_path = pjoin(self.repo.location, 'foo') + bin_path = pjoin(self.repo.location, "foo") touch(bin_path) self.assertNoReport(check, []) def test_regular_file(self): check = self.mk_check() - with open(pjoin(self.repo.location, 'foo'), 'w') as f: - f.write('bar') + with open(pjoin(self.repo.location, "foo"), "w") as f: + f.write("bar") self.assertNoReport(check, []) def test_unreadable_file(self): check = self.mk_check() - with open(pjoin(self.repo.location, 'foo'), 'w') as f: - f.write('bar') - with mock.patch('pkgcheck.open') as mocked_open: - mocked_open.side_effect = IOError('fake exception') + with open(pjoin(self.repo.location, "foo"), "w") as f: + f.write("bar") + with mock.patch("pkgcheck.open") as mocked_open: + mocked_open.side_effect = IOError("fake exception") self.assertNoReport(check, []) def test_ignored_root_dirs(self): for d in self.check_kls.ignored_root_dirs: check = self.mk_check() - bin_path = pjoin(self.repo.location, d, 'foo') + bin_path = pjoin(self.repo.location, d, "foo") os.makedirs(os.path.dirname(bin_path)) - with open(bin_path, 'wb') as f: - f.write(b'\xd3\xad\xbe\xef') + with open(bin_path, "wb") as f: + f.write(b"\xd3\xad\xbe\xef") self.assertNoReport(check, []) def test_null_bytes(self): check = self.mk_check() - with open(pjoin(self.repo.location, 'foo'), 'wb') as f: - f.write(b'foo\x00\xffbar') + with open(pjoin(self.repo.location, "foo"), "wb") as f: + f.write(b"foo\x00\xffbar") r = self.assertReport(check, []) assert isinstance(r, repo.BinaryFile) - assert r.path == 'foo' + assert r.path == "foo" assert "'foo'" in str(r) def test_root_dir_binary(self): check = self.mk_check() - bin_path = pjoin(self.repo.location, 'foo') - with open(bin_path, 'wb') as f: - f.write(b'\xd3\xad\xbe\xef') + bin_path = pjoin(self.repo.location, "foo") + with open(bin_path, "wb") as f: + f.write(b"\xd3\xad\xbe\xef") r = self.assertReport(check, []) assert isinstance(r, repo.BinaryFile) - assert r.path == 'foo' + assert r.path == "foo" assert "'foo'" in str(r) def test_ebuild_filesdir_binary(self): check = self.mk_check() - filesdir = self.mk_pkg('dev-util/foo') - with open(pjoin(filesdir, 'foo'), 'wb') as f: - f.write(b'\xd3\xad\xbe\xef') + filesdir = self.mk_pkg("dev-util/foo") + with open(pjoin(filesdir, "foo"), "wb") as f: + f.write(b"\xd3\xad\xbe\xef") r = self.assertReport(check, []) assert isinstance(r, repo.BinaryFile) - assert r.path == 'dev-util/foo/files/foo' + assert r.path == "dev-util/foo/files/foo" assert "'dev-util/foo/files/foo'" in str(r) def test_gitignore(self): # distfiles located in deprecated in-tree location are reported by default check = self.mk_check() - distfiles = pjoin(self.repo.location, 'distfiles') + distfiles = pjoin(self.repo.location, "distfiles") os.mkdir(distfiles) - with open(pjoin(distfiles, 'foo-0.tar.gz'), 'wb') as f: - f.write(b'\xd3\xad\xbe\xef') + with open(pjoin(distfiles, "foo-0.tar.gz"), "wb") as f: + f.write(b"\xd3\xad\xbe\xef") r = self.assertReport(check, []) assert isinstance(r, repo.BinaryFile) assert "distfiles/foo-0.tar.gz" in str(r) # but results are suppressed if a matching git ignore entry exists - for ignore_file in ('.gitignore', '.git/info/exclude'): + for ignore_file in (".gitignore", ".git/info/exclude"): path = pjoin(self.repo.location, ignore_file) ensure_dirs(os.path.dirname(path)) - with open(path, 'w') as f: - f.write('/distfiles/') + with open(path, "w") as f: + f.write("/distfiles/") self.assertNoReport(self.mk_check(), []) os.unlink(path) def test_non_utf8_encodings(self): # non-english languages courtesy of google translate mangling langs = ( - ("example text that shouldn't trigger", 'ascii'), - ('نص المثال الذي لا ينبغي أن يؤدي', 'cp1256'), # arabic - ('пример текста, который не должен срабатывать', 'koi8_r'), # russian - ('उदाहरण पाठ जो ट्रिगर नहीं होना चाहिए', 'utf-16'), # hindi - ('مثال کے متن جو ٹرگر نہ ہوں۔', 'utf-16'), # urdu - ('ဖြစ်ပေါ်မပေးသင့်ကြောင်းဥပမာစာသား', 'utf-32'), # burmese - ('उदाहरण पाठ जुन ट्रिगर हुँदैन', 'utf-32'), # nepali - ('トリガーするべきではないテキストの例', 'shift_jis'), # japanese - ('트리거해서는 안되는 예제 텍스트', 'cp949'), # korean - ('不应触发的示例文本', 'gb2312'), # simplified chinese - ('不應觸發的示例文本', 'gb18030'), # traditional chinese + ("example text that shouldn't trigger", "ascii"), + ("نص المثال الذي لا ينبغي أن يؤدي", "cp1256"), # arabic + ("пример текста, который не должен срабатывать", "koi8_r"), # russian + ("उदाहरण पाठ जो ट्रिगर नहीं होना चाहिए", "utf-16"), # hindi + ("مثال کے متن جو ٹرگر نہ ہوں۔", "utf-16"), # urdu + ("ဖြစ်ပေါ်မပေးသင့်ကြောင်းဥပမာစာသား", "utf-32"), # burmese + ("उदाहरण पाठ जुन ट्रिगर हुँदैन", "utf-32"), # nepali + ("トリガーするべきではないテキストの例", "shift_jis"), # japanese + ("트리거해서는 안되는 예제 텍스트", "cp949"), # korean + ("不应触发的示例文本", "gb2312"), # simplified chinese + ("不應觸發的示例文本", "gb18030"), # traditional chinese ) for text, encoding in langs: check = self.mk_check() - with open(pjoin(self.repo.location, 'foo'), 'wb') as f: + with open(pjoin(self.repo.location, "foo"), "wb") as f: data = text.encode(encoding) f.write(data) self.assertNoReport(check, []) |