Skip to content

Commit

Permalink
tests: Patch detect_releasevers, not detect_releasever
Browse files Browse the repository at this point in the history
  • Loading branch information
evan-goode committed Jan 27, 2025
1 parent 24e0072 commit 0758ec7
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
4 changes: 4 additions & 0 deletions tests/api/test_dnf_rpm.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ def test_detect_releasever(self):
# dnf.rpm.detect_releasever
self.assertHasAttr(dnf.rpm, "detect_releasever")

def test_detect_releasevers(self):
# dnf.rpm.detect_releasevers
self.assertHasAttr(dnf.rpm, "detect_releasevers")

def test_basearch(self):
# dnf.rpm.basearch
self.assertHasAttr(dnf.rpm, "basearch")
Expand Down
2 changes: 1 addition & 1 deletion tests/cli/commands/test_clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
'''
def _run(cli, args):
with mock.patch('sys.stdout', new_callable=StringIO), \
mock.patch('dnf.rpm.detect_releasever', return_value=69):
mock.patch('dnf.rpm.detect_releasevers', return_value=(69, None, None)):
cli.configure(['clean', '--config', '/dev/null'] + args)
cli.run()
Expand Down
2 changes: 1 addition & 1 deletion tests/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def command_run(cmd, args):

class Base(dnf.Base):
def __init__(self, *args, **kwargs):
with mock.patch('dnf.rpm.detect_releasever', return_value=69):
with mock.patch('dnf.rpm.detect_releasevers', return_value=(69, None, None)):
super(Base, self).__init__(*args, **kwargs)

# mock objects
Expand Down
4 changes: 2 additions & 2 deletions tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def test_instance(self):
self.assertIsNotNone(base)
base.close()

@mock.patch('dnf.rpm.detect_releasever', lambda x: 'x')
@mock.patch('dnf.rpm.detect_releasevers', lambda x: ('x', None, None))
@mock.patch('dnf.util.am_i_root', lambda: True)
def test_default_config_root(self):
base = dnf.Base()
Expand All @@ -67,7 +67,7 @@ def test_default_config_root(self):
self.assertIsNotNone(reg.match(base.conf.cachedir))
base.close()

@mock.patch('dnf.rpm.detect_releasever', lambda x: 'x')
@mock.patch('dnf.rpm.detect_releasevers', lambda x: ('x', None, None))
@mock.patch('dnf.util.am_i_root', lambda: False)
def test_default_config_user(self):
base = dnf.Base()
Expand Down
10 changes: 5 additions & 5 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def test_configure_user(self):
# call setUp() once again *after* am_i_root() is mocked so the cachedir is set as expected
self.setUp()
self.base._conf.installroot = self._installroot
with mock.patch('dnf.rpm.detect_releasever', return_value=69):
with mock.patch('dnf.rpm.detect_releasevers', return_value=(69, None, None)):
self.cli.configure(['update', '-c', self.conffile])
reg = re.compile('^' + self._installroot + '/var/tmp/dnf-[.a-zA-Z0-9_-]+$')
self.assertIsNotNone(reg.match(self.base.conf.cachedir))
Expand All @@ -203,7 +203,7 @@ def test_configure_user(self):
def test_configure_root(self):
""" Test Cli.configure as root."""
self.base._conf = dnf.conf.Conf()
with mock.patch('dnf.rpm.detect_releasever', return_value=69):
with mock.patch('dnf.rpm.detect_releasevers', return_value=(69, None, None)):
self.cli.configure(['update', '--nogpgcheck', '-c', self.conffile])
reg = re.compile('^/var/cache/dnf$')
self.assertIsNotNone(reg.match(self.base.conf.system_cachedir))
Expand All @@ -213,7 +213,7 @@ def test_configure_root(self):

def test_configure_verbose(self):
self.base._conf.installroot = self._installroot
with mock.patch('dnf.rpm.detect_releasever', return_value=69):
with mock.patch('dnf.rpm.detect_releasevers', return_value=(69, None, None)):
self.cli.configure(['-v', 'update', '-c', self.conffile])
parser = argparse.ArgumentParser()
expected = "%s -v update -c %s " % (parser.prog, self.conffile)
Expand All @@ -225,15 +225,15 @@ def test_configure_verbose(self):
@mock.patch('os.path.exists', return_value=True)
def test_conf_exists_in_installroot(self, ospathexists):
with mock.patch('logging.Logger.warning'), \
mock.patch('dnf.rpm.detect_releasever', return_value=69):
mock.patch('dnf.rpm.detect_releasevers', return_value=(69, None, None)):
self.cli.configure(['--installroot', '/roots/dnf', 'update'])
self.assertEqual(self.base.conf.config_file_path, '/roots/dnf/etc/dnf/dnf.conf')
self.assertEqual(self.base.conf.installroot, '/roots/dnf')

@mock.patch('dnf.cli.cli.Cli._parse_commands', new=mock.MagicMock)
@mock.patch('os.path.exists', return_value=False)
def test_conf_notexists_in_installroot(self, ospathexists):
with mock.patch('dnf.rpm.detect_releasever', return_value=69):
with mock.patch('dnf.rpm.detect_releasevers', return_value=(69, None, None)):
self.cli.configure(['--installroot', '/roots/dnf', 'update'])
self.assertEqual(self.base.conf.config_file_path, '/etc/dnf/dnf.conf')
self.assertEqual(self.base.conf.installroot, '/roots/dnf')
Expand Down

0 comments on commit 0758ec7

Please sign in to comment.