commit:     bed3311d84455ca49b45dc3146ecaf74d6ee8dc1
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Thu Feb 16 08:09:43 2023 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Sat Feb 18 10:13:35 2023 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=bed3311d

tests: news: drop usage of incomplete testdbapi, port to fakedbapi

It's been TODO for many years (see a4acda03bac43cc972dfaf9fda4d5210860d3d93)
and it covered up a problem with Display-If-Installed's test not actually
asserting if the package was installed or not.

Now e.g. dbapi.match() gives a proper result.

Bug: https://bugs.gentoo.org/889330
Signed-off-by: Sam James <sam <AT> gentoo.org>

 lib/portage/dbapi/virtual.py            | 19 -------------------
 lib/portage/tests/news/test_NewsItem.py | 10 ++++------
 2 files changed, 4 insertions(+), 25 deletions(-)

diff --git a/lib/portage/dbapi/virtual.py b/lib/portage/dbapi/virtual.py
index bba45f47d..2410ba1ed 100644
--- a/lib/portage/dbapi/virtual.py
+++ b/lib/portage/dbapi/virtual.py
@@ -212,22 +212,3 @@ class fakedbapi(dbapi):
         if metadata is None:
             raise KeyError(cpv)
         metadata.update(values)
-
-
-class testdbapi:
-    """A dbapi instance with completely fake functions to get by hitting disk
-    TODO(antarus):
-    This class really needs to be rewritten to have better stubs; but these 
work for now.
-    The dbapi classes themselves need unit tests...and that will be a lot of 
work.
-    """
-
-    def __init__(self):
-        self.cpvs = {}
-
-        def f(*args, **kwargs):
-            return True
-
-        fake_api = dir(dbapi)
-        for call in fake_api:
-            if not hasattr(self, call):
-                setattr(self, call, f)

diff --git a/lib/portage/tests/news/test_NewsItem.py 
b/lib/portage/tests/news/test_NewsItem.py
index 9324a7d18..53a9093de 100644
--- a/lib/portage/tests/news/test_NewsItem.py
+++ b/lib/portage/tests/news/test_NewsItem.py
@@ -5,7 +5,7 @@
 from portage import os
 from portage.tests import TestCase
 from portage.news import NewsItem
-from portage.dbapi.virtual import testdbapi
+from portage.dbapi.virtual import fakedbapi
 from tempfile import mkstemp
 
 from dataclasses import dataclass
@@ -81,8 +81,6 @@ class FakeNewsItem:
 
 
 class NewsItemTestCase(TestCase):
-    """These tests suck: they use your running config instead of making their 
own"""
-
     # Default values for testing
     placeholders = {
         "title": "YourSQL Upgrades from 4.0 to 4.1",
@@ -122,11 +120,10 @@ class NewsItemTestCase(TestCase):
     def setUp(self) -> None:
         self.profile = 
"/var/db/repos/gentoo/profiles/default-linux/x86/2007.0/"
         self.keywords = "x86"
-        # Use fake/test dbapi to avoid slow tests
-        self.vardb = testdbapi()
-        # self.vardb.inject_cpv('sys-apps/portage-2.0', { 'SLOT' : 0 })
         # Consumers only use ARCH, so avoid portage.settings by using a dict
         self.settings = {"ARCH": "x86"}
+        # Use fake/test dbapi to avoid slow tests
+        self.vardb = fakedbapi(self.settings)
 
     def _createNewsItem(self, *kwargs) -> FakeNewsItem:
         # Use our placeholders unless overridden
@@ -158,6 +155,7 @@ class NewsItemTestCase(TestCase):
             os.unlink(item.path)
 
     def testDisplayIfInstalled(self):
+        self.vardb.cpv_inject('sys-apps/portage-2.0', { 'SLOT' : "0" })
         tmpItem = self._createNewsItem({"display_if_installed": 
["sys-apps/portage"]})
 
         try:

Reply via email to