diff options
author | 2019-01-21 20:32:38 -0600 | |
---|---|---|
committer | 2019-01-21 20:32:38 -0600 | |
commit | 7fbf3a02cafa634cba48569788e256e34abc962d (patch) | |
tree | c9b396ff81f3e1c2451ae3b5e498759db35003d8 | |
parent | tests/sync: port all sync class tests to pytest (diff) | |
download | pkgcore-7fbf3a02cafa634cba48569788e256e34abc962d.tar.gz pkgcore-7fbf3a02cafa634cba48569788e256e34abc962d.tar.bz2 pkgcore-7fbf3a02cafa634cba48569788e256e34abc962d.zip |
tests/util: port tests to pytest
-rw-r--r-- | tests/util/test_commandline.py | 35 | ||||
-rw-r--r-- | tests/util/test_parserestrict.py | 35 |
2 files changed, 30 insertions, 40 deletions
diff --git a/tests/util/test_commandline.py b/tests/util/test_commandline.py index ed1d818e6..2500b9434 100644 --- a/tests/util/test_commandline.py +++ b/tests/util/test_commandline.py @@ -10,10 +10,11 @@ import pty import sys import unittest +import pytest + from pkgcore.config import central, errors from pkgcore.test.scripts.helpers import ArgParseMixin from pkgcore.util import commandline -from snakeoil.test import TestCase # Careful: the tests should not hit a load_config() call! @@ -38,7 +39,7 @@ class _Trigger(argparse.Action): namespace.empty_config = True -class ModifyConfigTest(TestCase, ArgParseMixin): +class TestModifyConfig(ArgParseMixin): parser = commandline.ArgumentParser(domain=False, version=False) parser.add_argument('--trigger', nargs=0, action=_Trigger) @@ -57,14 +58,14 @@ class ModifyConfigTest(TestCase, ArgParseMixin): return namespace def test_empty_config(self): - self.assertTrue(self.parse('--empty-config', '--trigger')) + assert self.parse('--empty-config', '--trigger') def test_modify_config(self): namespace = self.parse( '--empty-config', '--new-config', 'foo', 'class', 'tests.util.test_commandline.sect', '--trigger') - self.assertTrue(namespace.config.collapse_named_section('foo')) + assert namespace.config.collapse_named_section('foo') namespace = self.parse( '--empty-config', '--new-config', @@ -72,15 +73,14 @@ class ModifyConfigTest(TestCase, ArgParseMixin): '--add-config', 'foo', 'class', 'tests.util.test_commandline.sect', '--trigger') - self.assertTrue(namespace.config.collapse_named_section('foo')) + assert namespace.config.collapse_named_section('foo') namespace = self.parse( '--empty-config', '--add-config', 'foo', 'inherit', 'missing', '--trigger') - self.assertRaises( - errors.ConfigurationError, - namespace.config.collapse_named_section, 'foo') + with pytest.raises(errors.ConfigurationError): + namespace.config.collapse_named_section('foo') # This dance is currently necessary because commandline.main wants @@ -97,7 +97,7 @@ def _stream_and_getvalue(): return f, getvalue -class MainTest(TestCase): +class TestMain(object): def assertMain(self, status, outtext, errtext, subcmds, *args, **kwargs): out, out_getvalue = _stream_and_getvalue() @@ -105,11 +105,9 @@ class MainTest(TestCase): try: commandline.main(subcmds, outfile=out, errfile=err, *args, **kwargs) except SystemExit as e: - self.assertEqual(errtext, err_getvalue()) - self.assertEqual(outtext, out_getvalue()) - self.assertEqual( - status, e.args[0], - msg=f"expected status {status!r}, got {e.args[0]!r}") + assert errtext == err_getvalue() + assert outtext == out_getvalue() + assert status == e.args[0], f"expected status {status!r}, got {e.args[0]!r}" else: self.fail('no exception raised') @@ -183,7 +181,7 @@ class MainTest(TestCase): except SystemExit as e: # Important, without this reading the master fd blocks. out.close() - self.assertEqual(None, e.args[0]) + assert None == e.args[0] # There can be an xterm title update after this. # @@ -200,9 +198,8 @@ class MainTest(TestCase): raise master.close() - self.assertTrue( - out_name.startswith(out_kind) or out_name == 'PlainTextFormatter', - f'expected {out_kind!r}, got {out_name!r}') - self.assertEqual(err_kind, err_getvalue()) + assert out_name.startswith(out_kind) or out_name == 'PlainTextFormatter', \ + f'expected {out_kind!r}, got {out_name!r}' + assert err_kind == err_getvalue() else: self.fail('no exception raised') diff --git a/tests/util/test_parserestrict.py b/tests/util/test_parserestrict.py index e392ddd2a..191cdde8d 100644 --- a/tests/util/test_parserestrict.py +++ b/tests/util/test_parserestrict.py @@ -3,16 +3,16 @@ # License: BSD/GPL2 from snakeoil.currying import post_curry +import pytest from pkgcore.ebuild import restricts from pkgcore.ebuild.atom import atom from pkgcore.repository import util from pkgcore.restrictions import packages, values, boolean, restriction from pkgcore.util import parserestrict -from snakeoil.test import TestCase -class MatchTest(TestCase): +class TestMatch(object): def test_comma_separated_containment(self): parser = parserestrict.comma_separated_containment('utensil') @@ -26,12 +26,7 @@ class MatchTest(TestCase): assert not valrestrict.match(('foo',)) -class TestExtendedRestrictionGeneration(TestCase): - - def assertInstance(self, restrict, kls, token): - TestCase.assertInstance( - self, restrict, kls, - msg=f"got {restrict!r}, expected {kls!r} for {token!r}") +class TestExtendedRestrictionGeneration(object): def verify_text_glob(self, restrict, token): assert isinstance(restrict, values.StrRegex), token @@ -50,8 +45,8 @@ class TestExtendedRestrictionGeneration(TestCase): assert i == None, ( f"verifying None is returned on pointless restrictions, failed token: {token}") - self.assertRaises( - parserestrict.ParseError, parserestrict.convert_glob, '**') + with pytest.raises(parserestrict.ParseError): + parserestrict.convert_glob('**') def verify_restrict(self, restrict, attr, token): assert isinstance(restrict, packages.PackageRestriction), token @@ -156,7 +151,8 @@ class TestExtendedRestrictionGeneration(TestCase): self.verify_restrict(i[3], attr, token.split(":")[0].split("/")[n]) def test_atom_globbed(self): - assert isinstance(parserestrict.parse_match("=sys-devel/gcc-4*"), atom), "=sys-devel/gcc-4*" + assert isinstance( + parserestrict.parse_match("=sys-devel/gcc-4*"), atom), "=sys-devel/gcc-4*" def test_use_atom(self): o = parserestrict.parse_match("net-misc/openssh[-X]") @@ -185,21 +181,19 @@ class TestExtendedRestrictionGeneration(TestCase): self.verify_restrict(o[2], "package", token.split(":")[0]) def test_exceptions(self): - pm = parserestrict.parse_match - pe = parserestrict.ParseError for token in ( "!dev-util/diffball", "dev-util/diffball-0.4", - "=dev-util/*diffball-0.4", - "=*/diffball-0.4", + "=dev-util/*diffball-0.4*", "::gentoo", ): - self.assertRaises(pe, pm, token) + with pytest.raises(parserestrict.ParseError): + parserestrict.parse_match(token) -class ParsePVTest(TestCase): +class TestParsePV(object): - def setUp(self): + def setup_method(self, method): self.repo = util.SimpleTree({ 'spork': { 'foon': ('1', '2'), @@ -220,6 +214,5 @@ class ParsePVTest(TestCase): 'spork', 'foon-2', ): - self.assertRaises( - parserestrict.ParseError, - parserestrict.parse_pv, self.repo, bogus) + with pytest.raises(parserestrict.ParseError): + parserestrict.parse_pv(self.repo, bogus) |