Attached is a patch adding tests for debsources.fs_storage, whose coverage is now 95% (formerly 70%), as well as a patch adding tests for debsources.hashutil, whose coverage is now 100% (formerly 71%).
It might be a good idea to set the attribute of test_filetype, test_fs_storage and test_hashutil to 'utils' instead of a separate attribute for each of the test sets.
>From edf3fa8997667596a698a6f4fd29bc4f3268edf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Schreiner?= <clem...@mux.me> Date: Fri, 3 Apr 2015 08:30:47 +0200 Subject: [PATCH] Add tests for debsources.fs_storage. --- debsources/tests/test_fs_storage.py | 62 +++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 debsources/tests/test_fs_storage.py diff --git a/debsources/tests/test_fs_storage.py b/debsources/tests/test_fs_storage.py new file mode 100644 index 0000000..fbb62fa --- /dev/null +++ b/debsources/tests/test_fs_storage.py @@ -0,0 +1,62 @@ +# Copyright (C) 2013-2015 The Debsources developers <i...@sources.debian.net>. +# See the AUTHORS file at the top-level directory of this distribution and at +# https://anonscm.debian.org/gitweb/?p=qa/debsources.git;a=blob;f=AUTHORS;hb=HEAD +# +# This file is part of Debsources. Debsources is free software: you can +# redistribute it and/or modify it under the terms of the GNU Affero General +# Public License as published by the Free Software Foundation, either version 3 +# of the License, or (at your option) any later version. For more information +# see the COPYING file at the top-level directory of this distribution and at +# https://anonscm.debian.org/gitweb/?p=qa/debsources.git;a=blob;f=COPYING;hb=HEAD + +from __future__ import absolute_import + +import os.path +import unittest + +from nose.tools import istest +from nose.plugins.attrib import attr + +from debsources.fs_storage import parse_path, walk +from debsources.tests.testdata import * # NOQA + + +def make_path(path): + return os.path.join(TEST_DATA_DIR, 'sources', path) + + +@attr('fs_storage') +class FsStorageTests(unittest.TestCase): + """ Unit tests for debsources.fs """ + + @istest + def assertWalkLength(self): + self.assertEqual(len([f for f in walk(make_path(''))]), + 252) + + @istest + def assertWalkTestChecksums(self): + self.assertEqual( + len([f for f in walk(make_path(''), + test=lambda x: 'checksums' in x)]), + 36) + + @istest + def parsePathDir(self): + self.assertDictEqual( + parse_path(make_path('main/libc/libcaca/0.99.beta17-1')), + { + 'package': 'libcaca', + 'version': '0.99.beta17-1', + 'ext': None, + }) + + @istest + def parsePathChecksums(self): + self.assertDictEqual( + parse_path(make_path('main/libc/libcaca/0.99.beta17-1.checksums')), + { + 'package': 'libcaca', + 'version': '0.99.beta17-1', + 'ext': '.checksums', + }) -- 2.1.4
>From f5e01a9f25ee970d9065091c4a130f348dc1e68c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Schreiner?= <clem...@mux.me> Date: Fri, 3 Apr 2015 08:50:04 +0200 Subject: [PATCH] Add tests for debsources.hashutil. --- debsources/tests/test_hashutil.py | 42 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 debsources/tests/test_hashutil.py diff --git a/debsources/tests/test_hashutil.py b/debsources/tests/test_hashutil.py new file mode 100644 index 0000000..48a86e0 --- /dev/null +++ b/debsources/tests/test_hashutil.py @@ -0,0 +1,42 @@ +# Copyright (C) 2013-2015 The Debsources developers <i...@sources.debian.net>. +# See the AUTHORS file at the top-level directory of this distribution and at +# https://anonscm.debian.org/gitweb/?p=qa/debsources.git;a=blob;f=AUTHORS;hb=HEAD +# +# This file is part of Debsources. Debsources is free software: you can +# redistribute it and/or modify it under the terms of the GNU Affero General +# Public License as published by the Free Software Foundation, either version 3 +# of the License, or (at your option) any later version. For more information +# see the COPYING file at the top-level directory of this distribution and at +# https://anonscm.debian.org/gitweb/?p=qa/debsources.git;a=blob;f=COPYING;hb=HEAD + +from __future__ import absolute_import + +import os.path +import unittest + +from nose.tools import istest +from nose.plugins.attrib import attr + +from debsources.hashutil import sha1sum, sha256sum +from debsources.tests.testdata import * # NOQA + + +def make_path(path): + return os.path.join(TEST_DATA_DIR, 'sources', path) + + +@attr('hashutil') +class HashutilTests(unittest.TestCase): + """ Unit tests for debsources.hashutil """ + + @istest + def assertSha1Sum(self): + self.assertEqual( + sha1sum(make_path('main/libc/libcaca/0.99.beta18-1/COPYING')), + 'b57075f60950289e0f32be3145b74b7b17e6e5c5') + + @istest + def assertSha256Sum(self): + self.assertEqual( + sha256sum(make_path('main/libc/libcaca/0.99.beta18-1/COPYING')), + 'd10f0447c835a590ef137d99dd0e3ed29b5e032e7434a87315b30402bf14e7fd') -- 2.1.4