Skip to content

Commit

Permalink
tests: news: tiny cleanups
Browse files Browse the repository at this point in the history
Bug: https://bugs.gentoo.org/889330
Signed-off-by: Sam James <sam@gentoo.org>
  • Loading branch information
thesamesam committed Feb 16, 2023
1 parent 932170c commit e0809c1
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions 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
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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

Expand All @@ -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:
Expand Down Expand Up @@ -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())
Expand All @@ -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),
Expand Down

0 comments on commit e0809c1

Please sign in to comment.