1 |
commit: 98292b4077c0b75d7424955e0affa64beb86a2b7 |
2 |
Author: David Palao <david.palao <AT> gmail <DOT> com> |
3 |
AuthorDate: Fri Sep 23 13:41:02 2022 +0000 |
4 |
Commit: Mike Gilbert <floppym <AT> gentoo <DOT> org> |
5 |
CommitDate: Sun Sep 25 19:07:49 2022 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=98292b40 |
7 |
|
8 |
test(bintree): added some UTs for binarytree.__init__ |
9 |
|
10 |
Not very exhaustive, though, but they will help in future refactorings. |
11 |
|
12 |
Signed-off-by: David Palao <david.palao <AT> gmail.com> |
13 |
Signed-off-by: Mike Gilbert <floppym <AT> gentoo.org> |
14 |
|
15 |
lib/portage/tests/dbapi/test_bintree.py | 54 +++++++++++++++++++++++++++++++++ |
16 |
1 file changed, 54 insertions(+) |
17 |
|
18 |
diff --git a/lib/portage/tests/dbapi/test_bintree.py b/lib/portage/tests/dbapi/test_bintree.py |
19 |
new file mode 100644 |
20 |
index 000000000..14b89dfc0 |
21 |
--- /dev/null |
22 |
+++ b/lib/portage/tests/dbapi/test_bintree.py |
23 |
@@ -0,0 +1,54 @@ |
24 |
+# Copyright 2020-2022 Gentoo Authors |
25 |
+# Distributed under the terms of the GNU General Public License v2 |
26 |
+ |
27 |
+from unittest.mock import MagicMock |
28 |
+ |
29 |
+from portage.tests import TestCase |
30 |
+ |
31 |
+from portage.dbapi.bintree import binarytree |
32 |
+ |
33 |
+ |
34 |
+class BinarytreeTestCase(TestCase): |
35 |
+ def test_required_init_params(self): |
36 |
+ with self.assertRaises(TypeError) as cm: |
37 |
+ binarytree() |
38 |
+ self.assertEqual(str(cm.exception), "pkgdir parameter is required") |
39 |
+ with self.assertRaises(TypeError) as cm: |
40 |
+ binarytree(pkgdir="/tmp") |
41 |
+ self.assertEqual(str(cm.exception), "settings parameter is required") |
42 |
+ |
43 |
+ def test_init_with_legacy_params_warns(self): |
44 |
+ with self.assertWarns(DeprecationWarning): |
45 |
+ binarytree(_unused=None, pkgdir="/tmp", settings=MagicMock()) |
46 |
+ with self.assertWarns(DeprecationWarning): |
47 |
+ binarytree(virtual=None, pkgdir="/tmp", settings=MagicMock()) |
48 |
+ |
49 |
+ def test_instance_has_required_attrs(self): |
50 |
+ # Quite smoky test. What would it be a better testing strategy? |
51 |
+ # Not sure yet... |
52 |
+ required_attrs_no_multi_instance = { |
53 |
+ "pkgdir", "_multi_instance", "dbapi", "update_ents", |
54 |
+ "move_slot_ent", "populated", "tree", "_binrepos_conf", |
55 |
+ "_remote_has_index", "_remotepkgs", "_additional_pkgs", |
56 |
+ "invalids", "settings", "_pkg_paths", "_populating", |
57 |
+ "_all_directory", "_pkgindex_version", "_pkgindex_hashes", |
58 |
+ "_pkgindex_file", "_pkgindex_keys", "_pkgindex_aux_keys", |
59 |
+ "_pkgindex_use_evaluated_keys", "_pkgindex_header", |
60 |
+ "_pkgindex_header_keys", "_pkgindex_default_pkg_data", |
61 |
+ "_pkgindex_inherited_keys", "_pkgindex_default_header_data", |
62 |
+ "_pkgindex_translated_keys", "_pkgindex_allowed_pkg_keys", |
63 |
+ } |
64 |
+ no_multi_instance_settings = MagicMock() |
65 |
+ no_multi_instance_settings.features = "" |
66 |
+ no_multi_instance_bt = binarytree( |
67 |
+ pkgdir="/tmp", settings=no_multi_instance_settings) |
68 |
+ multi_instance_settings = MagicMock() |
69 |
+ multi_instance_settings.features = "binpkg-multi-instance" |
70 |
+ multi_instance_bt = binarytree( |
71 |
+ pkgdir="/tmp", settings=multi_instance_settings) |
72 |
+ for attr in required_attrs_no_multi_instance: |
73 |
+ getattr(no_multi_instance_bt, attr) |
74 |
+ getattr(multi_instance_bt, attr) |
75 |
+ # The next attribute is the difference between multi instance |
76 |
+ # and no multi instance: |
77 |
+ getattr(multi_instance_bt, "_allocate_filename") |