From 021c94eece3ad9f7303c00d6c75a8fd1c538be3d Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 7 May 2015 22:57:19 +0200 Subject: [PATCH] Rewrite test_enum.py to use pytest. See #660. --- tests/utils/usertypes/test_enum.py | 63 +++++++++++++----------------- 1 file changed, 28 insertions(+), 35 deletions(-) diff --git a/tests/utils/usertypes/test_enum.py b/tests/utils/usertypes/test_enum.py index ed9b6fb09..e1443b7be 100644 --- a/tests/utils/usertypes/test_enum.py +++ b/tests/utils/usertypes/test_enum.py @@ -19,45 +19,38 @@ """Tests for the Enum class.""" -import unittest - from qutebrowser.utils import usertypes +import pytest + # FIXME: Add some more tests, e.g. for is_int -class EnumTests(unittest.TestCase): - - """Test simple enums. - - Attributes: - enum: The enum we're testing. - """ - - def setUp(self): - self.enum = usertypes.enum('Enum', ['one', 'two']) - - def test_values(self): - """Test if enum members resolve to the right values.""" - self.assertEqual(self.enum.one.value, 1) - self.assertEqual(self.enum.two.value, 2) - - def test_name(self): - """Test .name mapping.""" - self.assertEqual(self.enum.one.name, 'one') - self.assertEqual(self.enum.two.name, 'two') - - def test_unknown(self): - """Test invalid values which should raise an AttributeError.""" - with self.assertRaises(AttributeError): - _ = self.enum.three - - def test_start(self): - """Test the start= argument.""" - e = usertypes.enum('Enum', ['three', 'four'], start=3) - self.assertEqual(e.three.value, 3) - self.assertEqual(e.four.value, 4) +@pytest.fixture +def enum(): + return usertypes.enum('Enum', ['one', 'two']) -if __name__ == '__main__': - unittest.main() +def test_values(enum): + """Test if enum members resolve to the right values.""" + assert enum.one.value == 1 + assert enum.two.value == 2 + + +def test_name(enum): + """Test .name mapping.""" + assert enum.one.name == 'one' + assert enum.two.name == 'two' + + +def test_unknown(enum): + """Test invalid values which should raise an AttributeError.""" + with pytest.raises(AttributeError): + _ = enum.three + + +def test_start(): + """Test the start= argument.""" + e = usertypes.enum('Enum', ['three', 'four'], start=3) + assert e.three.value == 3 + assert e.four.value == 4