From e0809c1759f3ac52ca8036bdba0db7ba4f24c4c9 Mon Sep 17 00:00:00 2001 From: Sam James Date: Thu, 16 Feb 2023 08:42:44 +0000 Subject: [PATCH] tests: news: tiny cleanups Bug: https://bugs.gentoo.org/889330 Signed-off-by: Sam James --- lib/portage/tests/news/test_NewsItem.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/portage/tests/news/test_NewsItem.py b/lib/portage/tests/news/test_NewsItem.py index 7fa19bb8e9..00017ab61d 100644 --- a/lib/portage/tests/news/test_NewsItem.py +++ b/lib/portage/tests/news/test_NewsItem.py @@ -1,12 +1,10 @@ # test_NewsItem.py -- Portage Unit Testing Functionality -# Copyright 2007-2019 Gentoo Authors +# Copyright 2007-2023 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 -from portage import os from portage.tests import TestCase from portage.news import NewsItem from portage.dbapi.virtual import fakedbapi -from tempfile import mkstemp from dataclasses import dataclass from string import Template @@ -18,7 +16,7 @@ # The specification for news items is GLEP 42 ("Critical News Reporting"): # https://www.gentoo.org/glep/glep-0042.html -# TODO: port the real newsitem class to this? + @dataclass class FakeNewsItem(NewsItem): title: str @@ -49,9 +47,11 @@ def __post_init__(self): super().__init__(path="mocked_news", name=self.title) def isValid(self): - with patch('builtins.open', mock_open(read_data=str(self))): + with patch("builtins.open", mock_open(read_data=str(self))): return super().isValid() + # TODO: Migrate __str__ to NewsItem? NewsItem doesn't actually parse + # all fields right now though. def __str__(self) -> str: item = self.item_template_header.substitute( title=self.title, @@ -71,8 +71,7 @@ def __str__(self) -> str: for keyword in self.display_if_keyword: item += f"Display-If-Keyword: {keyword}\n" - item += "\n" - item += f"{self.content}" + item += f"\n{self.content}" return item @@ -98,11 +97,11 @@ class NewsItemTestCase(TestCase): Please see the Gentoo YourSQL Upgrade Guide for instructions: - http://www.gentoo.org/doc/en/yoursql-upgrading.xml + https://gentoo.org/doc/en/yoursql-upgrading.xml Also see the official YourSQL documentation: - http://dev.yoursql.com/doc/refman/4.1/en/upgrading-from-4-0.html + https://dev.example.com/doc/refman/4.1/en/upgrading-from-4-0.html After upgrading, you should also recompile any packages which link against YourSQL: @@ -159,7 +158,7 @@ def testDisplayIfProfile(self): ) def testDisplayIfInstalled(self): - self.vardb.cpv_inject('sys-apps/portage-2.0', {'SLOT': "0"}) + self.vardb.cpv_inject("sys-apps/portage-2.0", {"SLOT": "0"}) item = self._createNewsItem({"display_if_installed": ["sys-apps/portage"]}) self.assertTrue(item.isValid()) @@ -170,7 +169,9 @@ def testDisplayIfInstalled(self): # Test the negative case: a single Display-If-Installed listing # a package we don't have. - item = self._createNewsItem({"display_if_installed": ["sys-apps/i-do-not-exist"]}) + item = self._createNewsItem( + {"display_if_installed": ["sys-apps/i-do-not-exist"]} + ) self.assertTrue(item.isValid()) self.assertFalse( item.isRelevant(self.vardb, self.settings, self.profile),