├── unittest2pytest ├── fixes │ ├── __init__.py │ ├── fix_remove_class.py │ └── fix_self_assert.py ├── __init__.py ├── __main__.py └── utils.py ├── tests ├── fixtures │ ├── simple_out.py │ ├── remove_class │ │ ├── assertEqual_out.py │ │ └── assertEqual_in.py │ ├── simple_in.py │ └── self_assert │ │ ├── assertItemsEqual_in.py │ │ ├── assertItemsEqual_out.py │ │ ├── assertListEqual_out.py │ │ ├── assertMultiLineEqual_out.py │ │ ├── assertWarns_in.py │ │ ├── assertRegex_in.py │ │ ├── assertRegex_out.py │ │ ├── fail_in.py │ │ ├── assertRegexpMatches_out.py │ │ ├── assertNotRegex_in.py │ │ ├── assertNotRegex_out.py │ │ ├── fail_out.py │ │ ├── assertListEqual_in.py │ │ ├── assertRegexpMatches_in.py │ │ ├── assertIn_out.py │ │ ├── assertIs_out.py │ │ ├── assertLess_out.py │ │ ├── assertGreater_out.py │ │ ├── assertLessEqual_out.py │ │ ├── assertGreaterEqual_out.py │ │ ├── assertWarns_out.py │ │ ├── assertIsNot_out.py │ │ ├── assertMultiLineEqual_in.py │ │ ├── assertNotIn_out.py │ │ ├── assertNotEqual_out.py │ │ ├── assertIn_in.py │ │ ├── assertIs_in.py │ │ ├── assertLess_in.py │ │ ├── assertIsNot_in.py │ │ ├── assertNotIn_in.py │ │ ├── assertIsInstance_out.py │ │ ├── assertGreater_in.py │ │ ├── assertLessEqual_in.py │ │ ├── assertNotIsInstance_out.py │ │ ├── assertIsInstance_in.py │ │ ├── assertWarnsRegex_in.py │ │ ├── assertDictContainsSubset_out.py │ │ ├── assertDictContainsSubset_in.py │ │ ├── assertTupleEqual_out.py │ │ ├── assertDictEqual_out.py │ │ ├── assertGreaterEqual_in.py │ │ ├── assertNotEqual_in.py │ │ ├── assertNotIsInstance_in.py │ │ ├── assertSetEqual_out.py │ │ ├── assertIsNone_out.py │ │ ├── assertWarnsRegex_out.py │ │ ├── assertIsNone_in.py │ │ ├── assertIsNotNone_out.py │ │ ├── assertSetEqual_in.py │ │ ├── assertTrue_out.py │ │ ├── assertDictEqual_in.py │ │ ├── assertTupleEqual_in.py │ │ ├── assertIsNotNone_in.py │ │ ├── assertFalse_out.py │ │ ├── assertTrue_in.py │ │ ├── assertFalse_in.py │ │ ├── assertEqual_out.py │ │ ├── assertAlmostEqual_out.py │ │ ├── assertNotAlmostEqual_out.py │ │ ├── assertSequenceEqual_out.py │ │ ├── assertAlmostEqual_in.py │ │ ├── assertNotAlmostEqual_in.py │ │ ├── assertEqual_in.py │ │ ├── assertSequenceEqual_in.py │ │ ├── assertRaisesRegex_in.py │ │ ├── assertRaisesRegexp_in.py │ │ ├── assertRaisesRegex_out.py │ │ ├── assertRaisesRegexp_out.py │ │ ├── assertRaises_in.py │ │ └── assertRaises_out.py ├── requirements.txt └── test_all_fixes.py ├── MANIFEST.in ├── setup.cfg ├── tox.ini ├── .github ├── dependabot.yml └── workflows │ ├── deploy.yml │ └── test.yml ├── DEVELOPER.rst ├── .gitignore ├── AUTHORS.txt ├── RELEASING.rst ├── CHANGELOG.rst ├── setup.py ├── README.rst └── COPYING-GPLv3.txt /unittest2pytest/fixes/__init__.py: -------------------------------------------------------------------------------- 1 | # 2 | -------------------------------------------------------------------------------- /tests/fixtures/simple_out.py: -------------------------------------------------------------------------------- 1 | def test_you(self): 2 | assert abc == 'xxx' 3 | 4 | 5 | 6 | def test_you(self): 7 | assert abc != 'xxx' 8 | -------------------------------------------------------------------------------- /tests/fixtures/remove_class/assertEqual_out.py: -------------------------------------------------------------------------------- 1 | def test_you(self): 2 | self.assertEqual(abc, 'xxx') 3 | 4 | 5 | 6 | def test_you(self): 7 | self.assertNotEqual(abc, 'xxx') 8 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include CHANGELOG.rst 2 | include COPYING-GPLv3.txt 3 | include README.rst 4 | 5 | recursive-include tests * 6 | recursive-exclude * __pycache__ 7 | recursive-exclude * *.py[co] 8 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [zest.releaser] 2 | python-file-with-version = unittest2pytest/__init__.py 3 | push-changes = no 4 | tag-format = v{version} 5 | tag-message = unittest2pytest {version} 6 | tag-signing = yes 7 | -------------------------------------------------------------------------------- /tests/fixtures/simple_in.py: -------------------------------------------------------------------------------- 1 | class TestAssertEqual(TestCase): 2 | def test_you(self): 3 | self.assertEqual(abc, 'xxx') 4 | 5 | 6 | class TestAssertNotEqual(TestCase): 7 | 8 | def test_you(self): 9 | self.assertNotEqual(abc, 'xxx') 10 | -------------------------------------------------------------------------------- /tests/fixtures/remove_class/assertEqual_in.py: -------------------------------------------------------------------------------- 1 | class TestAssertEqual(TestCase): 2 | def test_you(self): 3 | self.assertEqual(abc, 'xxx') 4 | 5 | 6 | class TestAssertNotEqual(TestCase): 7 | 8 | def test_you(self): 9 | self.assertNotEqual(abc, 'xxx') 10 | -------------------------------------------------------------------------------- /tox.ini: -------------------------------------------------------------------------------- 1 | # Tox (https://tox.readthedocs.io) is a tool for running tests 2 | # in multiple virtualenvs. This configuration file will run the 3 | # test suite on all supported python versions. To use it, "pip install tox" 4 | # and then run "tox" from this directory. 5 | 6 | [tox] 7 | envlist = py39, py310, py311, py312 8 | 9 | [testenv] 10 | deps = 11 | pytest 12 | commands = pytest {posargs} 13 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertItemsEqual_in.py: -------------------------------------------------------------------------------- 1 | # required-method: assertItemsEqual 2 | 3 | class TestItemsEqual(TestCase): 4 | def test_simple(self): 5 | self.assertItemsEqual(a, b) 6 | 7 | def test_simple_msg(self): 8 | self.assertItemsEqual(a, b, msg="This is wrong!") 9 | 10 | def test_simple_msg2(self): 11 | self.assertItemsEqual(a, b, "This is wrong!") 12 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertItemsEqual_out.py: -------------------------------------------------------------------------------- 1 | # required-method: assertItemsEqual 2 | 3 | class TestItemsEqual(TestCase): 4 | def test_simple(self): 5 | assert sorted(a) == sorted(b) 6 | 7 | def test_simple_msg(self): 8 | assert sorted(a) == sorted(b), "This is wrong!" 9 | 10 | def test_simple_msg2(self): 11 | assert sorted(a) == sorted(b), "This is wrong!" 12 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertListEqual_out.py: -------------------------------------------------------------------------------- 1 | # required-method: assertListEqual 2 | 3 | class TestListEqual(TestCase): 4 | def test_simple(self): 5 | assert 100 == klm 6 | assert 456 == (aaa and bbb) 7 | assert 789 == (ccc or ddd) 8 | assert 123 == (True if You else False) 9 | 10 | def test_simple_msg(self): 11 | assert klm == 100, "This is wrong!" 12 | 13 | def test_simple_msg2(self): 14 | assert klm == 100, "This is wrong!" 15 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertMultiLineEqual_out.py: -------------------------------------------------------------------------------- 1 | # required-method: assertMultiLineEqual 2 | 3 | class TestMultiLineEqual(TestCase): 4 | def test_simple(self): 5 | assert 100 == klm 6 | assert 456 == (aaa and bbb) 7 | assert 789 == (ccc or ddd) 8 | assert 123 == (True if You else False) 9 | 10 | def test_simple_msg(self): 11 | assert klm == 100, "This is wrong!" 12 | 13 | def test_simple_msg2(self): 14 | assert klm == 100, "This is wrong!" 15 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertWarns_in.py: -------------------------------------------------------------------------------- 1 | # required-method: assertWarns 2 | 3 | class TestWarns(TestCase): 4 | def test_simple(self): 5 | self.assertWarns(RunTimeError, someFunc) 6 | 7 | def test_args(self): 8 | self.assertWarns(RunTimeError, someFunc, 1,2,3) 9 | 10 | def test_kwargs(self): 11 | self.assertWarns(RunTimeError, someFunc, foo=42, bar=43) 12 | 13 | def test_args_kwargs(self): 14 | self.assertWarns(RunTimeError, someFunc, 1,2,3, foo=42, bar=43) 15 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertRegex_in.py: -------------------------------------------------------------------------------- 1 | # required-method: assertRegex 2 | 3 | class TestAssertEqual(TestCase): 4 | def test_you(self): 5 | self.assertRegex(abc, 'xxx') 6 | 7 | def test_me(self): 8 | self.assertRegex(123, xxx+y) 9 | 10 | def test_everybody(self): 11 | self.assertRegex( 'abc' , 'def' ) 12 | 13 | def test_message(self): 14 | self.assertRegex(123+z, xxx+y, msg='This is wrong!') 15 | self.assertRegex(123, xxx+y, 'This is wrong!') 16 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertRegex_out.py: -------------------------------------------------------------------------------- 1 | # required-method: assertRegex 2 | 3 | import re 4 | class TestAssertEqual(TestCase): 5 | def test_you(self): 6 | assert re.search('xxx', abc) 7 | 8 | def test_me(self): 9 | assert re.search(xxx+y, 123) 10 | 11 | def test_everybody(self): 12 | assert re.search('def', 'abc') 13 | 14 | def test_message(self): 15 | assert re.search(xxx+y, 123+z), 'This is wrong!' 16 | assert re.search(xxx+y, 123), 'This is wrong!' 17 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/fail_in.py: -------------------------------------------------------------------------------- 1 | # required-method: fail 2 | 3 | class TestAssertTrue(TestCase): 4 | def test_me(self): 5 | self.fail(xxx+y) 6 | self.fail(aaa % bbb) 7 | self.fail(ccc or ddd) 8 | 9 | def test_everybody(self): 10 | self.fail( 'abc' ) 11 | 12 | def test_message(self): 13 | self.fail(msg='This is wrong!') 14 | self.fail(error_message) 15 | 16 | def test_nothing(self): 17 | self.fail() 18 | self.fail(self.fail()) 19 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertRegexpMatches_out.py: -------------------------------------------------------------------------------- 1 | # required-method: assertRegexpMatches 2 | 3 | import re 4 | class TestAssertEqual(TestCase): 5 | def test_you(self): 6 | assert re.search('xxx', abc) 7 | 8 | def test_me(self): 9 | assert re.search(xxx+y, 123) 10 | 11 | def test_everybody(self): 12 | assert re.search('def', 'abc') 13 | 14 | def test_message(self): 15 | assert re.search(xxx+y, 123+z), 'This is wrong!' 16 | assert re.search(xxx+y, 123), 'This is wrong!' 17 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertNotRegex_in.py: -------------------------------------------------------------------------------- 1 | # required-method: assertNotRegex 2 | 3 | class TestAssertEqual(TestCase): 4 | def test_you(self): 5 | self.assertNotRegex(abc, 'xxx') 6 | 7 | def test_me(self): 8 | self.assertNotRegex(123, xxx+y) 9 | 10 | def test_everybody(self): 11 | self.assertNotRegex( 'abc' , 'def' ) 12 | 13 | def test_message(self): 14 | self.assertNotRegex(123+z, xxx+y, msg='This is wrong!') 15 | self.assertNotRegex(123, xxx+y, 'This is wrong!') 16 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertNotRegex_out.py: -------------------------------------------------------------------------------- 1 | # required-method: assertNotRegex 2 | 3 | import re 4 | class TestAssertEqual(TestCase): 5 | def test_you(self): 6 | assert not re.search('xxx', abc) 7 | 8 | def test_me(self): 9 | assert not re.search(xxx+y, 123) 10 | 11 | def test_everybody(self): 12 | assert not re.search('def', 'abc') 13 | 14 | def test_message(self): 15 | assert not re.search(xxx+y, 123+z), 'This is wrong!' 16 | assert not re.search(xxx+y, 123), 'This is wrong!' 17 | -------------------------------------------------------------------------------- /tests/requirements.txt: -------------------------------------------------------------------------------- 1 | # For running tests 2 | pytest >= 3.3.0 # Testing framework. 3 | 4 | # Helper tools 5 | zest.releaser # Makes releasing easier 6 | wheel # For creating .whl packages in Appveyour to avoid compiling again. 7 | check-manifest # Checks MANIFEST.in 8 | pyroma # Checks if package follows best practices of Python packaging. 9 | chardet # character encoding detector. 10 | readme # Check PYPI description. 11 | twine # For secure upload of tar.gz to PYPI. 12 | pycmd # Contains 'py.cleanup' that removes all .pyc files and similar. 13 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/fail_out.py: -------------------------------------------------------------------------------- 1 | # required-method: fail 2 | 3 | import pytest 4 | class TestAssertTrue(TestCase): 5 | def test_me(self): 6 | pytest.fail(xxx+y) 7 | pytest.fail(aaa % bbb) 8 | pytest.fail(ccc or ddd) 9 | 10 | def test_everybody(self): 11 | pytest.fail( 'abc' ) 12 | 13 | def test_message(self): 14 | pytest.fail(msg='This is wrong!') 15 | pytest.fail(error_message) 16 | 17 | def test_nothing(self): 18 | pytest.fail() 19 | pytest.fail(pytest.fail()) 20 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertListEqual_in.py: -------------------------------------------------------------------------------- 1 | # required-method: assertListEqual 2 | 3 | class TestListEqual(TestCase): 4 | def test_simple(self): 5 | self.assertListEqual(100, klm) 6 | self.assertListEqual(456, aaa and bbb) 7 | self.assertListEqual(789, ccc or ddd) 8 | self.assertListEqual(123, True if You else False) 9 | 10 | def test_simple_msg(self): 11 | self.assertListEqual(klm, 100, msg="This is wrong!") 12 | 13 | def test_simple_msg2(self): 14 | self.assertListEqual(klm, 100, "This is wrong!") 15 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertRegexpMatches_in.py: -------------------------------------------------------------------------------- 1 | # required-method: assertRegexpMatches 2 | 3 | class TestAssertEqual(TestCase): 4 | def test_you(self): 5 | self.assertRegexpMatches(abc, 'xxx') 6 | 7 | def test_me(self): 8 | self.assertRegexpMatches(123, xxx+y) 9 | 10 | def test_everybody(self): 11 | self.assertRegexpMatches( 'abc' , 'def' ) 12 | 13 | def test_message(self): 14 | self.assertRegexpMatches(123+z, xxx+y, msg='This is wrong!') 15 | self.assertRegexpMatches(123, xxx+y, 'This is wrong!') 16 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertIn_out.py: -------------------------------------------------------------------------------- 1 | # required-method: assertIn 2 | 3 | class TestAssertIn(TestCase): 4 | def test_you(self): 5 | assert abc in 'xxx' 6 | 7 | def test_me(self): 8 | assert 123 in xxx+y 9 | assert 456 in (aaa and bbb) 10 | assert 789 in (ccc or ddd) 11 | assert 123 in (True if You else False) 12 | 13 | def test_everybody(self): 14 | assert 'abc' in 'def' 15 | 16 | def test_message(self): 17 | assert 123 in xxx+z, 'This is wrong!' 18 | assert 123+z in xxx+z, 'This is wrong!' 19 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertIs_out.py: -------------------------------------------------------------------------------- 1 | # required-method: assertIs 2 | 3 | class TestAssertIs(TestCase): 4 | def test_you(self): 5 | assert abc is 'xxx' 6 | 7 | def test_me(self): 8 | assert 123 is xxx+y 9 | assert 456 is (aaa and bbb) 10 | assert 789 is (ccc or ddd) 11 | assert 123 is (True if You else False) 12 | 13 | def test_everybody(self): 14 | assert 'abc' is 'def' 15 | 16 | def test_message(self): 17 | assert 123+z is xxx+z, 'This is wrong!' 18 | assert 123 is xxx+z, 'This is wrong!' 19 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertLess_out.py: -------------------------------------------------------------------------------- 1 | # required-method: assertLess 2 | 3 | class TestAssertLess(TestCase): 4 | def test_you(self): 5 | assert abc < 'xxx' 6 | 7 | def test_me(self): 8 | assert 123 < xxx+y 9 | assert 456 < (aaa and bbb) 10 | assert 789 < (ccc or ddd) 11 | assert 123 < (True if You else False) 12 | 13 | def test_everybody(self): 14 | assert 'abc' < 'def' 15 | 16 | def test_message(self): 17 | assert 123+z < xxx+z, 'This is wrong!' 18 | assert 123 < xxx+z, 'This is wrong!' 19 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertGreater_out.py: -------------------------------------------------------------------------------- 1 | # required-method: assertGreater 2 | 3 | class TestAssertGreater(TestCase): 4 | def test_you(self): 5 | assert abc > 'xxx' 6 | 7 | def test_me(self): 8 | assert 123 > xxx+y 9 | assert 456 > (aaa and bbb) 10 | assert 789 > (ccc or ddd) 11 | assert 123 > (True if You else False) 12 | 13 | def test_everybody(self): 14 | assert 'abc' > 'def' 15 | 16 | def test_message(self): 17 | assert 123+z > xxx+z, 'This is wrong!' 18 | assert 123 > xxx+z, 'This is wrong!' 19 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertLessEqual_out.py: -------------------------------------------------------------------------------- 1 | # required-method: assertLessEqual 2 | 3 | class TestAssertLessEqual(TestCase): 4 | def test_you(self): 5 | assert abc <= 'xxx' 6 | 7 | def test_me(self): 8 | assert 123 <= xxx+y 9 | assert 456 <= (aaa and bbb) 10 | assert 789 <= (ccc or ddd) 11 | assert 123 <= (True if You else False) 12 | 13 | def test_everybody(self): 14 | assert 'abc' <= 'def' 15 | 16 | def test_message(self): 17 | assert 123+z <= xxx+z, error_message 18 | assert 123 <= xxx+z, error_message 19 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertGreaterEqual_out.py: -------------------------------------------------------------------------------- 1 | # required-method: assertGreaterEqual 2 | 3 | class TestAssertGreaterEqual(TestCase): 4 | def test_you(self): 5 | assert abc >= 'xxx' 6 | 7 | def test_me(self): 8 | assert 123 >= xxx+y 9 | assert 456 >= (aaa and bbb) 10 | assert 789 >= (ccc or ddd) 11 | assert 123 >= (True if You else False) 12 | 13 | def test_everybody(self): 14 | assert 'abc' >= 'def' 15 | 16 | def test_message(self): 17 | assert 123+z >= xxx+z, error_message 18 | assert 123 >= xxx+z, error_message 19 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertWarns_out.py: -------------------------------------------------------------------------------- 1 | # required-method: assertWarns 2 | 3 | import pytest 4 | class TestWarns(TestCase): 5 | def test_simple(self): 6 | with pytest.warns(RunTimeError): 7 | someFunc() 8 | 9 | def test_args(self): 10 | with pytest.warns(RunTimeError): 11 | someFunc(1,2,3) 12 | 13 | def test_kwargs(self): 14 | with pytest.warns(RunTimeError): 15 | someFunc(foo=42, bar=43) 16 | 17 | def test_args_kwargs(self): 18 | with pytest.warns(RunTimeError): 19 | someFunc(1,2,3, foo=42, bar=43) 20 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertIsNot_out.py: -------------------------------------------------------------------------------- 1 | # required-method: assertIsNot 2 | 3 | class TestAssertIsNot(TestCase): 4 | def test_you(self): 5 | assert abc is not 'xxx' 6 | 7 | def test_me(self): 8 | assert 123 is not xxx+y 9 | assert 456 is not (aaa and bbb) 10 | assert 789 is not (ccc or ddd) 11 | assert 123 is not (True if You else False) 12 | 13 | def test_everybody(self): 14 | assert 'abc' is not 'def' 15 | 16 | def test_message(self): 17 | assert 123+z is not xxx+z, error_message 18 | assert 123 is not xxx+z, error_message 19 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertMultiLineEqual_in.py: -------------------------------------------------------------------------------- 1 | # required-method: assertMultiLineEqual 2 | 3 | class TestMultiLineEqual(TestCase): 4 | def test_simple(self): 5 | self.assertMultiLineEqual(100, klm) 6 | self.assertMultiLineEqual(456, aaa and bbb) 7 | self.assertMultiLineEqual(789, ccc or ddd) 8 | self.assertMultiLineEqual(123, True if You else False) 9 | 10 | def test_simple_msg(self): 11 | self.assertMultiLineEqual(klm, 100, msg="This is wrong!") 12 | 13 | def test_simple_msg2(self): 14 | self.assertMultiLineEqual(klm, 100, "This is wrong!") 15 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertNotIn_out.py: -------------------------------------------------------------------------------- 1 | # required-method: assertNotIn 2 | 3 | class TestAssertNotIn(TestCase): 4 | def test_you(self): 5 | assert abc not in 'xxx' 6 | 7 | def test_me(self): 8 | assert 123 not in xxx+y 9 | assert 456 not in (aaa and bbb) 10 | assert 789 not in (ccc or ddd) 11 | assert 123 not in (True if You else False) 12 | 13 | def test_everybody(self): 14 | assert 'abc' not in 'def' 15 | 16 | def test_message(self): 17 | assert 123+z not in xxx+z, error_message 18 | assert 123 not in xxx+z, error_message 19 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertNotEqual_out.py: -------------------------------------------------------------------------------- 1 | # required-method: assertNotEqual 2 | 3 | class TestAssertNotEqual(TestCase): 4 | def test_you(self): 5 | assert abc != 'xxx' 6 | assert abc != 'xxx' 7 | 8 | def test_me(self): 9 | assert 123 != xxx+y 10 | assert 456 != (aaa and bbb) 11 | assert 789 != (ccc or ddd) 12 | assert 123 != (True if You else False) 13 | 14 | def test_everybody(self): 15 | assert 'abc' != 'def' 16 | 17 | def test_message(self): 18 | assert 123+z != xxx+z, error_message 19 | assert 123 != xxx+z, error_message 20 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertIn_in.py: -------------------------------------------------------------------------------- 1 | # required-method: assertIn 2 | 3 | class TestAssertIn(TestCase): 4 | def test_you(self): 5 | self.assertIn(abc, 'xxx') 6 | 7 | def test_me(self): 8 | self.assertIn(123, xxx+y) 9 | self.assertIn(456, aaa and bbb) 10 | self.assertIn(789, ccc or ddd) 11 | self.assertIn(123, True if You else False) 12 | 13 | def test_everybody(self): 14 | self.assertIn( 'abc' , 'def' ) 15 | 16 | def test_message(self): 17 | self.assertIn(123, xxx+z, 'This is wrong!') 18 | self.assertIn(123+z, xxx+z, msg='This is wrong!') 19 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertIs_in.py: -------------------------------------------------------------------------------- 1 | # required-method: assertIs 2 | 3 | class TestAssertIs(TestCase): 4 | def test_you(self): 5 | self.assertIs(abc, 'xxx') 6 | 7 | def test_me(self): 8 | self.assertIs(123, xxx+y) 9 | self.assertIs(456, aaa and bbb) 10 | self.assertIs(789, ccc or ddd) 11 | self.assertIs(123, True if You else False) 12 | 13 | def test_everybody(self): 14 | self.assertIs( 'abc' , 'def' ) 15 | 16 | def test_message(self): 17 | self.assertIs(123+z, xxx+z, msg='This is wrong!') 18 | self.assertIs(123, xxx+z, 'This is wrong!') 19 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # Keep GitHub Actions up to date with GitHub's Dependabot... 2 | # https://docs.github.com/en/code-security/dependabot/working-with-dependabot/keeping-your-actions-up-to-date-with-dependabot 3 | # https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file#package-ecosystem 4 | version: 2 5 | updates: 6 | - package-ecosystem: github-actions 7 | directory: / 8 | groups: 9 | github-actions: 10 | patterns: 11 | - "*" # Group all Actions updates into a single larger pull request 12 | schedule: 13 | interval: weekly 14 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertLess_in.py: -------------------------------------------------------------------------------- 1 | # required-method: assertLess 2 | 3 | class TestAssertLess(TestCase): 4 | def test_you(self): 5 | self.assertLess(abc, 'xxx') 6 | 7 | def test_me(self): 8 | self.assertLess(123, xxx+y) 9 | self.assertLess(456, aaa and bbb) 10 | self.assertLess(789, ccc or ddd) 11 | self.assertLess(123, True if You else False) 12 | 13 | def test_everybody(self): 14 | self.assertLess( 'abc' , 'def' ) 15 | 16 | def test_message(self): 17 | self.assertLess(123+z, xxx+z, msg='This is wrong!') 18 | self.assertLess(123, xxx+z, 'This is wrong!') 19 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertIsNot_in.py: -------------------------------------------------------------------------------- 1 | # required-method: assertIsNot 2 | 3 | class TestAssertIsNot(TestCase): 4 | def test_you(self): 5 | self.assertIsNot(abc, 'xxx') 6 | 7 | def test_me(self): 8 | self.assertIsNot(123, xxx+y) 9 | self.assertIsNot(456, aaa and bbb) 10 | self.assertIsNot(789, ccc or ddd) 11 | self.assertIsNot(123, True if You else False) 12 | 13 | def test_everybody(self): 14 | self.assertIsNot( 'abc' , 'def' ) 15 | 16 | def test_message(self): 17 | self.assertIsNot(123+z, xxx+z, msg=error_message) 18 | self.assertIsNot(123, xxx+z, error_message) 19 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertNotIn_in.py: -------------------------------------------------------------------------------- 1 | # required-method: assertNotIn 2 | 3 | class TestAssertNotIn(TestCase): 4 | def test_you(self): 5 | self.assertNotIn(abc, 'xxx') 6 | 7 | def test_me(self): 8 | self.assertNotIn(123, xxx+y) 9 | self.assertNotIn(456, aaa and bbb) 10 | self.assertNotIn(789, ccc or ddd) 11 | self.assertNotIn(123, True if You else False) 12 | 13 | def test_everybody(self): 14 | self.assertNotIn( 'abc' , 'def' ) 15 | 16 | def test_message(self): 17 | self.assertNotIn(123+z, xxx+z, msg=error_message) 18 | self.assertNotIn(123, xxx+z, error_message) 19 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertIsInstance_out.py: -------------------------------------------------------------------------------- 1 | # required-method: assertIsInstance 2 | 3 | class TestAssertIsInstance(TestCase): 4 | def test_you(self): 5 | assert isinstance(abc, 'xxx') 6 | 7 | def test_me(self): 8 | assert isinstance(123, xxx+y) 9 | assert isinstance(456, aaa and bbb) 10 | assert isinstance(789, ccc or ddd) 11 | assert isinstance(123, True if You else False) 12 | 13 | def test_everybody(self): 14 | assert isinstance('abc', 'def') 15 | 16 | def test_message(self): 17 | assert isinstance(123+z, xxx+z), 'This is wrong!' 18 | assert isinstance(123, xxx+z), 'This is wrong!' 19 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertGreater_in.py: -------------------------------------------------------------------------------- 1 | # required-method: assertGreater 2 | 3 | class TestAssertGreater(TestCase): 4 | def test_you(self): 5 | self.assertGreater(abc, 'xxx') 6 | 7 | def test_me(self): 8 | self.assertGreater(123, xxx+y) 9 | self.assertGreater(456, aaa and bbb) 10 | self.assertGreater(789, ccc or ddd) 11 | self.assertGreater(123, True if You else False) 12 | 13 | def test_everybody(self): 14 | self.assertGreater( 'abc' , 'def' ) 15 | 16 | def test_message(self): 17 | self.assertGreater(123+z, xxx+z, msg='This is wrong!') 18 | self.assertGreater(123, xxx+z, 'This is wrong!') 19 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertLessEqual_in.py: -------------------------------------------------------------------------------- 1 | # required-method: assertLessEqual 2 | 3 | class TestAssertLessEqual(TestCase): 4 | def test_you(self): 5 | self.assertLessEqual(abc, 'xxx') 6 | 7 | def test_me(self): 8 | self.assertLessEqual(123, xxx+y) 9 | self.assertLessEqual(456, aaa and bbb) 10 | self.assertLessEqual(789, ccc or ddd) 11 | self.assertLessEqual(123, True if You else False) 12 | 13 | def test_everybody(self): 14 | self.assertLessEqual( 'abc' , 'def' ) 15 | 16 | def test_message(self): 17 | self.assertLessEqual(123+z, xxx+z, msg=error_message) 18 | self.assertLessEqual(123, xxx+z, error_message) 19 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertNotIsInstance_out.py: -------------------------------------------------------------------------------- 1 | # required-method: assertNotIsInstance 2 | 3 | class TestAssertNotIsInstance(TestCase): 4 | def test_you(self): 5 | assert not isinstance(abc, 'xxx') 6 | 7 | def test_me(self): 8 | assert not isinstance(123, xxx+y) 9 | assert not isinstance(456, aaa and bbb) 10 | assert not isinstance(789, ccc or ddd) 11 | assert not isinstance(123, True if You else False) 12 | 13 | def test_everybody(self): 14 | assert not isinstance('abc', 'def') 15 | 16 | def test_message(self): 17 | assert not isinstance(123+z, xxx+z), error_message 18 | assert not isinstance(123, xxx+z), error_message 19 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertIsInstance_in.py: -------------------------------------------------------------------------------- 1 | # required-method: assertIsInstance 2 | 3 | class TestAssertIsInstance(TestCase): 4 | def test_you(self): 5 | self.assertIsInstance(abc, 'xxx') 6 | 7 | def test_me(self): 8 | self.assertIsInstance(123, xxx+y) 9 | self.assertIsInstance(456, aaa and bbb) 10 | self.assertIsInstance(789, ccc or ddd) 11 | self.assertIsInstance(123, True if You else False) 12 | 13 | def test_everybody(self): 14 | self.assertIsInstance( 'abc' , 'def' ) 15 | 16 | def test_message(self): 17 | self.assertIsInstance(123+z, xxx+z, msg='This is wrong!') 18 | self.assertIsInstance(123, xxx+z, 'This is wrong!') 19 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertWarnsRegex_in.py: -------------------------------------------------------------------------------- 1 | # required-method: assertWarnsRegex 2 | 3 | class TestWarns(TestCase): 4 | def test_simple(self): 5 | self.assertWarnsRegex(RunTimeError, pattern, someFunc) 6 | 7 | def test_args(self): 8 | self.assertWarnsRegex(RunTimeError, pattern, someFunc, 1,2,3) 9 | 10 | def test_kwargs(self): 11 | self.assertWarnsRegex(RunTimeError, pattern, someFunc, foo=42, bar=43) 12 | 13 | def test_args_kwargs(self): 14 | self.assertWarnsRegex(RunTimeError, pattern, someFunc, 1,2,3, foo=42, bar=43) 15 | 16 | def test_context_manager(self): 17 | with self.assertWarnsRegex(RunTimeError, pattern): 18 | someFunc(1, 2, 3) 19 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertDictContainsSubset_out.py: -------------------------------------------------------------------------------- 1 | # required-method: assertDictContainsSubset 2 | 3 | class TestDictEqual(TestCase): 4 | def test_simple(self): 5 | assert {**superset, **{'a: 1'}} == superset 6 | 7 | def test_simple_msg(self): 8 | assert {**{'a: 1'}, **subset} == {'a: 1'}, "This is wrong!" 9 | 10 | def test_simple_msg2(self): 11 | assert {**{'a: 1'}, **subset} == {'a: 1'}, "This is wrong!" 12 | 13 | def test_line_wrapping(self): 14 | assert {**{ 15 | 'a': 1, 16 | 'b': 2, 17 | }, **{'b': 2}} == { 18 | 'a': 1, 19 | 'b': 2, 20 | }, \ 21 | "This is wrong!" 22 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertDictContainsSubset_in.py: -------------------------------------------------------------------------------- 1 | # required-method: assertDictContainsSubset 2 | 3 | class TestDictEqual(TestCase): 4 | def test_simple(self): 5 | self.assertDictContainsSubset({'a: 1'}, superset) 6 | 7 | def test_simple_msg(self): 8 | self.assertDictContainsSubset(subset, {'a: 1'}, msg="This is wrong!") 9 | 10 | def test_simple_msg2(self): 11 | self.assertDictContainsSubset(subset, {'a: 1'}, "This is wrong!") 12 | 13 | def test_line_wrapping(self): 14 | self.assertDictContainsSubset( 15 | {'b': 2}, 16 | { 17 | 'a': 1, 18 | 'b': 2, 19 | }, 20 | "This is wrong!", 21 | ) 22 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertTupleEqual_out.py: -------------------------------------------------------------------------------- 1 | # required-method: assertTupleEqual 2 | 3 | class TestTupleEqual(TestCase): 4 | def test_simple(self): 5 | assert 100 == klm 6 | assert 456 == (aaa and bbb) 7 | assert 789 == (ccc or ddd) 8 | assert 123 == (True if You else False) 9 | 10 | def test_simple_msg(self): 11 | assert klm == 100, "This is wrong!" 12 | 13 | def test_simple_msg2(self): 14 | assert klm == 100, "This is wrong!" 15 | 16 | def test_line_wrapping(self): 17 | assert ( 18 | 'a', 19 | 'b' 20 | ) == \ 21 | ('b',), \ 22 | "This is wrong!" 23 | 24 | assert 100 == klm 25 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertDictEqual_out.py: -------------------------------------------------------------------------------- 1 | # required-method: assertDictEqual 2 | 3 | class TestDictEqual(TestCase): 4 | def test_simple(self): 5 | assert 100 == klm 6 | assert 456 == (aaa and bbb) 7 | assert 789 == (ccc or ddd) 8 | assert 123 == (True if You else False) 9 | 10 | def test_simple_msg(self): 11 | assert klm == 100, "This is wrong!" 12 | 13 | def test_simple_msg2(self): 14 | assert klm == 100, "This is wrong!" 15 | 16 | def test_line_wrapping(self): 17 | assert { 18 | 'a': 1, 19 | 'b': 2, 20 | } == \ 21 | {'b': 2}, \ 22 | "This is wrong!" 23 | 24 | assert 100 == klm 25 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertGreaterEqual_in.py: -------------------------------------------------------------------------------- 1 | # required-method: assertGreaterEqual 2 | 3 | class TestAssertGreaterEqual(TestCase): 4 | def test_you(self): 5 | self.assertGreaterEqual(abc, 'xxx') 6 | 7 | def test_me(self): 8 | self.assertGreaterEqual(123, xxx+y) 9 | self.assertGreaterEqual(456, aaa and bbb) 10 | self.assertGreaterEqual(789, ccc or ddd) 11 | self.assertGreaterEqual(123, True if You else False) 12 | 13 | def test_everybody(self): 14 | self.assertGreaterEqual( 'abc' , 'def' ) 15 | 16 | def test_message(self): 17 | self.assertGreaterEqual(123+z, xxx+z, msg=error_message) 18 | self.assertGreaterEqual(123, xxx+z, error_message) 19 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertNotEqual_in.py: -------------------------------------------------------------------------------- 1 | # required-method: assertNotEqual 2 | 3 | class TestAssertNotEqual(TestCase): 4 | def test_you(self): 5 | self.assertNotEqual(abc, 'xxx') 6 | self.assertNotEquals(abc, 'xxx') 7 | 8 | def test_me(self): 9 | self.assertNotEqual(123, xxx+y) 10 | self.assertNotEqual(456, aaa and bbb) 11 | self.assertNotEqual(789, ccc or ddd) 12 | self.assertNotEqual(123, True if You else False) 13 | 14 | def test_everybody(self): 15 | self.assertNotEqual( 'abc' , 'def' ) 16 | 17 | def test_message(self): 18 | self.assertNotEqual(123+z, xxx+z, msg=error_message) 19 | self.assertNotEqual(123, xxx+z, error_message) 20 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertNotIsInstance_in.py: -------------------------------------------------------------------------------- 1 | # required-method: assertNotIsInstance 2 | 3 | class TestAssertNotIsInstance(TestCase): 4 | def test_you(self): 5 | self.assertNotIsInstance(abc, 'xxx') 6 | 7 | def test_me(self): 8 | self.assertNotIsInstance(123, xxx+y) 9 | self.assertNotIsInstance(456, aaa and bbb) 10 | self.assertNotIsInstance(789, ccc or ddd) 11 | self.assertNotIsInstance(123, True if You else False) 12 | 13 | def test_everybody(self): 14 | self.assertNotIsInstance( 'abc' , 'def' ) 15 | 16 | def test_message(self): 17 | self.assertNotIsInstance(123+z, xxx+z, msg=error_message) 18 | self.assertNotIsInstance(123, xxx+z, error_message) 19 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertSetEqual_out.py: -------------------------------------------------------------------------------- 1 | # required-method: assertSetEqual 2 | 3 | class TestSetEqual(TestCase): 4 | def test_simple(self): 5 | assert 100 == klm 6 | assert 456 == (aaa and bbb) 7 | assert 789 == (ccc or ddd) 8 | assert 123 == (True if You else False) 9 | 10 | def test_simple_msg(self): 11 | assert klm == 100, "This is wrong!" 12 | 13 | def test_simple_msg2(self): 14 | assert klm == 100, "This is wrong!" 15 | 16 | def test_line_wrapping(self): 17 | assert set( 18 | [ 19 | 'a', 20 | 'b' 21 | ]) == \ 22 | set(['b']), \ 23 | "This is wrong!" 24 | 25 | assert 100 == klm 26 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertIsNone_out.py: -------------------------------------------------------------------------------- 1 | # required-method: assertIsNone 2 | 3 | class TestAssertIsNone(TestCase): 4 | def test_you(self): 5 | assert abc is None 6 | 7 | def test_me(self): 8 | assert xxx+y is None 9 | assert (aaa and bbb) is None 10 | assert (ccc or ddd) is None 11 | assert (True if You else False) is None 12 | 13 | def test_everybody(self): 14 | assert 'abc' is None 15 | 16 | def test_message(self): 17 | assert 123+z is None, 'This is wrong!' 18 | assert xxx+z is None, error_message 19 | 20 | def test_generator(self): 21 | assert (x for x in range(1)) is None 22 | assert (x for x in range(1)) is None 23 | assert (x for x in range(1)) is None, "This is wrong" 24 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertWarnsRegex_out.py: -------------------------------------------------------------------------------- 1 | # required-method: assertWarnsRegex 2 | 3 | import pytest 4 | class TestWarns(TestCase): 5 | def test_simple(self): 6 | with pytest.warns(RunTimeError, match=pattern): 7 | someFunc() 8 | 9 | def test_args(self): 10 | with pytest.warns(RunTimeError, match=pattern): 11 | someFunc(1,2,3) 12 | 13 | def test_kwargs(self): 14 | with pytest.warns(RunTimeError, match=pattern): 15 | someFunc(foo=42, bar=43) 16 | 17 | def test_args_kwargs(self): 18 | with pytest.warns(RunTimeError, match=pattern): 19 | someFunc(1,2,3, foo=42, bar=43) 20 | 21 | def test_context_manager(self): 22 | with pytest.warns(RunTimeError, match=pattern): 23 | someFunc(1, 2, 3) 24 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertIsNone_in.py: -------------------------------------------------------------------------------- 1 | # required-method: assertIsNone 2 | 3 | class TestAssertIsNone(TestCase): 4 | def test_you(self): 5 | self.assertIsNone(abc) 6 | 7 | def test_me(self): 8 | self.assertIsNone(xxx+y) 9 | self.assertIsNone(aaa and bbb) 10 | self.assertIsNone(ccc or ddd) 11 | self.assertIsNone(True if You else False) 12 | 13 | def test_everybody(self): 14 | self.assertIsNone( 'abc' ) 15 | 16 | def test_message(self): 17 | self.assertIsNone(123+z, msg='This is wrong!') 18 | self.assertIsNone(xxx+z, error_message) 19 | 20 | def test_generator(self): 21 | self.assertIsNone((x for x in range(1))) 22 | self.assertIsNone(x for x in range(1)) 23 | self.assertIsNone((x for x in range(1)), "This is wrong") 24 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertIsNotNone_out.py: -------------------------------------------------------------------------------- 1 | # required-method: assertIsNotNone 2 | 3 | class TestAssertIsNotNone(TestCase): 4 | def test_you(self): 5 | assert abc is not None 6 | 7 | def test_me(self): 8 | assert xxx+y is not None 9 | assert (aaa and bbb) is not None 10 | assert (ccc or ddd) is not None 11 | assert (True if You else False) is not None 12 | 13 | def test_everybody(self): 14 | assert 'def' is not None 15 | 16 | def test_message(self): 17 | assert 123+z is not None, error_message 18 | assert xxx+z is not None, 'This is wrong!' 19 | 20 | def test_generator(self): 21 | assert (x for x in range(1)) is not None 22 | assert (x for x in range(1)) is not None 23 | assert (x for x in range(1)) is not None, "This is wrong" 24 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertSetEqual_in.py: -------------------------------------------------------------------------------- 1 | # required-method: assertSetEqual 2 | 3 | class TestSetEqual(TestCase): 4 | def test_simple(self): 5 | self.assertSetEqual(100, klm) 6 | self.assertSetEqual(456, aaa and bbb) 7 | self.assertSetEqual(789, ccc or ddd) 8 | self.assertSetEqual(123, True if You else False) 9 | 10 | def test_simple_msg(self): 11 | self.assertSetEqual(klm, 100, msg="This is wrong!") 12 | 13 | def test_simple_msg2(self): 14 | self.assertSetEqual(klm, 100, "This is wrong!") 15 | 16 | def test_line_wrapping(self): 17 | self.assertSetEqual(set( 18 | [ 19 | 'a', 20 | 'b' 21 | ]), 22 | set(['b']), 23 | "This is wrong!", 24 | ) 25 | 26 | self.assertSetEqual(100, klm) 27 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertTrue_out.py: -------------------------------------------------------------------------------- 1 | # required-method: assertTrue 2 | 3 | class TestAssertTrue(TestCase): 4 | def test_you(self): 5 | assert abc 6 | 7 | def test_me(self): 8 | assert xxx+y 9 | assert aaa and bbb 10 | assert ccc or ddd 11 | assert True if You else False 12 | 13 | def test_everybody(self): 14 | assert 'abc' 15 | 16 | def test_message(self): 17 | assert 123+z, 'This is wrong!' 18 | assert xxx+z, error_message 19 | 20 | def test_expression_as_argument(self): 21 | assert abc not in self.data 22 | assert abc in self.data 23 | assert not contains 24 | 25 | def test_generator(self): 26 | assert (x for x in range(1)) 27 | assert (x for x in range(1)) 28 | assert (x for x in range(1)), "This is wrong" 29 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertDictEqual_in.py: -------------------------------------------------------------------------------- 1 | # required-method: assertDictEqual 2 | 3 | class TestDictEqual(TestCase): 4 | def test_simple(self): 5 | self.assertDictEqual(100, klm) 6 | self.assertDictEqual(456, aaa and bbb) 7 | self.assertDictEqual(789, ccc or ddd) 8 | self.assertDictEqual(123, True if You else False) 9 | 10 | def test_simple_msg(self): 11 | self.assertDictEqual(klm, 100, msg="This is wrong!") 12 | 13 | def test_simple_msg2(self): 14 | self.assertDictEqual(klm, 100, "This is wrong!") 15 | 16 | def test_line_wrapping(self): 17 | self.assertDictEqual( 18 | { 19 | 'a': 1, 20 | 'b': 2, 21 | }, 22 | {'b': 2}, 23 | "This is wrong!", 24 | ) 25 | 26 | self.assertDictEqual(100, klm) 27 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertTupleEqual_in.py: -------------------------------------------------------------------------------- 1 | # required-method: assertTupleEqual 2 | 3 | class TestTupleEqual(TestCase): 4 | def test_simple(self): 5 | self.assertTupleEqual(100, klm) 6 | self.assertTupleEqual(456, aaa and bbb) 7 | self.assertTupleEqual(789, ccc or ddd) 8 | self.assertTupleEqual(123, True if You else False) 9 | 10 | def test_simple_msg(self): 11 | self.assertTupleEqual(klm, 100, msg="This is wrong!") 12 | 13 | def test_simple_msg2(self): 14 | self.assertTupleEqual(klm, 100, "This is wrong!") 15 | 16 | def test_line_wrapping(self): 17 | self.assertTupleEqual( 18 | ( 19 | 'a', 20 | 'b' 21 | ), 22 | ('b',), 23 | "This is wrong!", 24 | ) 25 | 26 | self.assertTupleEqual(100, klm) 27 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertIsNotNone_in.py: -------------------------------------------------------------------------------- 1 | # required-method: assertIsNotNone 2 | 3 | class TestAssertIsNotNone(TestCase): 4 | def test_you(self): 5 | self.assertIsNotNone(abc) 6 | 7 | def test_me(self): 8 | self.assertIsNotNone(xxx+y) 9 | self.assertIsNotNone(aaa and bbb) 10 | self.assertIsNotNone(ccc or ddd) 11 | self.assertIsNotNone(True if You else False) 12 | 13 | def test_everybody(self): 14 | self.assertIsNotNone( 'def' ) 15 | 16 | def test_message(self): 17 | self.assertIsNotNone(123+z, msg=error_message) 18 | self.assertIsNotNone(xxx+z, 'This is wrong!') 19 | 20 | def test_generator(self): 21 | self.assertIsNotNone((x for x in range(1))) 22 | self.assertIsNotNone(x for x in range(1)) 23 | self.assertIsNotNone((x for x in range(1)), "This is wrong") 24 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertFalse_out.py: -------------------------------------------------------------------------------- 1 | # required-method: assertFalse 2 | 3 | class TestAssertFalse(TestCase): 4 | def test_you(self): 5 | assert not abc 6 | 7 | def test_me(self): 8 | assert not xxx+y 9 | assert not (aaa and bbb) 10 | assert not (ccc or ddd) 11 | assert not (True if You else False) 12 | 13 | def test_everybody(self): 14 | assert not 'def' 15 | 16 | def test_message(self): 17 | assert not 123+z, error_message 18 | assert not xxx+z, 'This is wrong!' 19 | 20 | def test_expression_as_argument(self): 21 | assert not (abc not in self.data) 22 | assert not (abc in self.data) 23 | assert not (not contains) 24 | 25 | def test_generator(self): 26 | assert not (x for x in range(1)) 27 | assert not (x for x in range(1)) 28 | assert not (x for x in range(1)), "This is wrong" 29 | -------------------------------------------------------------------------------- /DEVELOPER.rst: -------------------------------------------------------------------------------- 1 | 2 | Testing 3 | =========== 4 | 5 | Continuous integration tests are available at 6 | https://github.com/pytest-dev/unittest2pytest/actions. 7 | 8 | Prior to pushing a pull request to GitHub, please test locally:: 9 | 10 | pip install tox pytest 11 | tox -e py 12 | 13 | 14 | Version Scheme 15 | ================= 16 | 17 | Regarding the version scheme, unittest2pytest conforms to :PEP:`440`. 18 | This basically means that releases will look like `0.3`, `0.3.1`, 19 | `0.4`, and pre-releases will have versions like `0.3.dev1`, 20 | `0.3.1.dev0`. 21 | 22 | 23 | 24 | 25 | .. _PyPI: https://pypi.python.org/ 26 | .. _TestPyPI: https://testpypi.python.org/pypi 27 | .. |unittest2pytest@PyPI| replace:: unittest2pytest at PyPI 28 | .. _unittest2pytest@PyPI: https://pypi.python.org/unittest2pytest 29 | 30 | .. 31 | Local Variables: 32 | mode: rst 33 | ispell-local-dictionary: "american" 34 | coding: utf-8 35 | End: 36 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # crazy-compiler standard excludes 2 | /projectlogo.png 3 | /docs/_build/ 4 | *.[1-9] 5 | 6 | # editor artefacts 7 | *~ 8 | .#* 9 | \#*# 10 | .*.swp 11 | 12 | # build artefacts 13 | /.sconf_temp 14 | /.sconsign.* 15 | /config.h 16 | /config.log 17 | /config.status 18 | /autom4te*.cache 19 | /options.cache 20 | /stamp-h1 21 | 22 | # C, C++ build artefacts 23 | *.[oa] 24 | *.l[oa] 25 | *.al 26 | .libs 27 | .deps 28 | *.so 29 | *.so.[0-9]* 30 | *.rej 31 | 32 | *.dll 33 | .idea 34 | 35 | # Python build artefacts 36 | /build/ 37 | /dist/ 38 | /_venv/ 39 | *.py[cod] 40 | *.egg 41 | *.egg-info 42 | *.egg-link 43 | 44 | /nosetests.xml 45 | /.cache 46 | /.coverage 47 | /.pytest_cache 48 | /.tox 49 | /.achievements 50 | /.installed.cfg 51 | /.ropeproject 52 | 53 | # Mr Developer 54 | /.mr.developer.cfg 55 | /.project 56 | /.pydevproject 57 | 58 | # OS generated files 59 | *.DS_[sS]Store* 60 | ehthumbs.db 61 | Icon? 62 | Thumbs.db 63 | *.pid 64 | ._.**~ 65 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertTrue_in.py: -------------------------------------------------------------------------------- 1 | # required-method: assertTrue 2 | 3 | class TestAssertTrue(TestCase): 4 | def test_you(self): 5 | self.assertTrue(abc) 6 | 7 | def test_me(self): 8 | self.assertTrue(xxx+y) 9 | self.assertTrue(aaa and bbb) 10 | self.assertTrue(ccc or ddd) 11 | self.assertTrue(True if You else False) 12 | 13 | def test_everybody(self): 14 | self.assertTrue( 'abc' ) 15 | 16 | def test_message(self): 17 | self.assertTrue(123+z, msg='This is wrong!') 18 | self.assertTrue(xxx+z, error_message) 19 | 20 | def test_expression_as_argument(self): 21 | self.assertTrue(abc not in self.data) 22 | self.assertTrue(abc in self.data) 23 | self.assertTrue(not contains) 24 | 25 | def test_generator(self): 26 | self.assertTrue((x for x in range(1))) 27 | self.assertTrue(x for x in range(1)) 28 | self.assertTrue((x for x in range(1)), "This is wrong") 29 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertFalse_in.py: -------------------------------------------------------------------------------- 1 | # required-method: assertFalse 2 | 3 | class TestAssertFalse(TestCase): 4 | def test_you(self): 5 | self.assertFalse(abc) 6 | 7 | def test_me(self): 8 | self.assertFalse(xxx+y) 9 | self.assertFalse(aaa and bbb) 10 | self.assertFalse(ccc or ddd) 11 | self.assertFalse(True if You else False) 12 | 13 | def test_everybody(self): 14 | self.assertFalse( 'def' ) 15 | 16 | def test_message(self): 17 | self.assertFalse(123+z, msg=error_message) 18 | self.assertFalse(xxx+z, 'This is wrong!') 19 | 20 | def test_expression_as_argument(self): 21 | self.assertFalse(abc not in self.data) 22 | self.assertFalse(abc in self.data) 23 | self.assertFalse(not contains) 24 | 25 | def test_generator(self): 26 | self.assertFalse((x for x in range(1))) 27 | self.assertFalse(x for x in range(1)) 28 | self.assertFalse((x for x in range(1)), "This is wrong") 29 | -------------------------------------------------------------------------------- /AUTHORS.txt: -------------------------------------------------------------------------------- 1 | Contributors 2 | ============== 3 | 4 | The number im front of each name denotes the number of commits by the 5 | respective contributor. 6 | 7 | Contributors for v0.4 8 | ------------------------ 9 | 10 | 25 Hartmut Goebel 11 | 6 Jon Dufresne 12 | 2 Thomas Grainger 13 | 1 Aaron Godfrey 14 | 1 Joshua Howard 15 | 16 | 17 | Contributors for v0.3 18 | ------------------------ 19 | 20 | 6 Guilherme Quentel Melo 21 | 3 Adam Chainz 22 | 3 Ronny Pfannschmidt 23 | 1 Hartmut Goebel 24 | 25 | 26 | Contributors for v0.2 27 | ------------------------ 28 | 29 | 17 Hartmut Goebel 30 | 31 | 32 | Contributors for v0.1 33 | ------------------------ 34 | 35 | 36 Hartmut Goebel 36 | 37 | .. 38 | Local Variables: 39 | ispell-local-dictionary: "american" 40 | coding: utf-8 41 | End: 42 | -------------------------------------------------------------------------------- /unittest2pytest/__init__.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2015-2019 by Hartmut Goebel 3 | # 4 | # This file is part of unittest2pytest. 5 | # 6 | # unittest2pytest is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, but 12 | # WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | # 19 | 20 | __author__ = "Hartmut Goebel " 21 | __copyright__ = "Copyright 2015-2019 by Hartmut Goebel" 22 | __licence__ = "GNU General Public License version 3 or later (GPLv3+)" 23 | 24 | 25 | __title__ = 'unittest2pytest' 26 | __version__ = '0.6.dev0' 27 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertEqual_out.py: -------------------------------------------------------------------------------- 1 | # required-method: assertEqual 2 | 3 | class TestAssertEqual(TestCase): 4 | def test_you(self): 5 | assert abc == 'xxx' 6 | assert abc == 'xxx' 7 | 8 | def test_me(self): 9 | assert 123 == xxx+y 10 | assert 456 == (aaa and bbb) 11 | assert 789 == (ccc or ddd) 12 | assert 123 == (True if You else False) 13 | 14 | def test_everybody(self): 15 | assert 'abc' == 'def' 16 | 17 | def test_message(self): 18 | assert 123+z == xxx+y, 'This is wrong!' 19 | assert 123 == xxx+y, 'This is wrong!' 20 | 21 | def test_line_wrapping(self): 22 | assert True == False, 'This will fail %s' % \ 23 | 'always' 24 | 25 | assert 'abc' \ 26 | .replace( 27 | 'abc' 28 | , 'def') == \ 29 | 'def', \ 30 | 'Wrap %s' % \ 31 | 'everything' 32 | 33 | def test_expression_as_argument(self): 34 | assert (abc not in self.data) == True 35 | assert (abc in self.data) == (not contains) 36 | assert contains == (not contains) 37 | -------------------------------------------------------------------------------- /unittest2pytest/__main__.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2015-2019 by Hartmut Goebel 3 | # 4 | # This file is part of unittest2pytest. 5 | # 6 | # unittest2pytest is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, but 12 | # WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | # 19 | 20 | __author__ = "Hartmut Goebel " 21 | __copyright__ = "Copyright 2015-2019 by Hartmut Goebel" 22 | __licence__ = "GNU General Public License version 3 or later (GPLv3+)" 23 | 24 | 25 | import lib2to3.main 26 | from . import fixes 27 | 28 | def main(): 29 | raise SystemExit(lib2to3.main.main(fixes.__name__)) 30 | 31 | if __name__ == '__main__': 32 | main() 33 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertAlmostEqual_out.py: -------------------------------------------------------------------------------- 1 | # required-method: assertAlmostEqual 2 | 3 | class TestAlmostAssertEqual(TestCase): 4 | def test_simple(self): 5 | assert round(abs(100-klm), 7) == 0 6 | assert round(abs(456-(aaa and bbb)), 7) == 0 7 | assert round(abs(789-(ccc or ddd)), 7) == 0 8 | assert round(abs(123-(True if You else False)), 7) == 0 9 | 10 | def test_simple_msg(self): 11 | assert round(abs(klm-100), 7) == 0, "This is wrong!" 12 | 13 | def test_places(self): 14 | assert round(abs(50+x-klm), 1) == 0 15 | 16 | def test_places_msg(self): 17 | assert round(abs(klm-100), 1) == 0, error_message 18 | 19 | def test_places_kw(self): 20 | assert round(abs(100-klm), 1) == 0 21 | 22 | def test_places_kw_msg(self): 23 | assert round(abs(klm-50+x), 1) == 0, "This is wrong!" 24 | 25 | def test_places_kw_msg2(self): 26 | assert round(abs(100-klm), 1) == 0, error_message 27 | 28 | 29 | def test_delta_kw(self): 30 | assert abs(klm-100.01) < 1 31 | 32 | def test_delta_kw_msg(self): 33 | assert abs(50+x-klm) < 1, "This is wrong!" 34 | 35 | def test_delta_kw_msg2(self): 36 | assert abs(klm-100) < 1, error_message 37 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertNotAlmostEqual_out.py: -------------------------------------------------------------------------------- 1 | # required-method: assertNotAlmostEqual 2 | 3 | class TestAssertNotAlmostEqual(TestCase): 4 | def test_simple(self): 5 | assert round(abs(100-klm), 7) != 0 6 | assert round(abs(456-(aaa and bbb)), 7) != 0 7 | assert round(abs(789-(ccc or ddd)), 7) != 0 8 | assert round(abs(123-(True if You else False)), 7) != 0 9 | 10 | def test_simple_msg(self): 11 | assert round(abs(klm-50+x), 7) != 0, "This is wrong!" 12 | 13 | def test_places(self): 14 | assert round(abs(100-klm), 1) != 0 15 | 16 | def test_places_msg(self): 17 | assert round(abs(klm-100), 1) != 0, error_message 18 | 19 | def test_places_kw(self): 20 | assert round(abs(50+x-klm), 1) != 0 21 | 22 | def test_places_kw_msg(self): 23 | assert round(abs(klm-100), 1) != 0, "This is wrong!" 24 | 25 | def test_places_kw_msg2(self): 26 | assert round(abs(100-klm), 1) != 0, error_message 27 | 28 | 29 | def test_delta_kw(self): 30 | assert abs(klm-50+x) > 1 31 | 32 | def test_delta_kw_msg(self): 33 | assert abs(100-klm) > 1, "This is wrong!" 34 | 35 | def test_delta_kw_msg2(self): 36 | assert abs(klm-100) > 1, error_message 37 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertSequenceEqual_out.py: -------------------------------------------------------------------------------- 1 | # required-method: assertSequenceEqual 2 | 3 | class TestSequenceEqual(TestCase): 4 | def test_simple(self): 5 | assert 100 == klm 6 | assert 456 == (aaa and bbb) 7 | assert 789 == (ccc or ddd) 8 | assert 123 == (True if You else False) 9 | 10 | def test_simple_msg(self): 11 | assert klm == 100, "This is wrong!" 12 | 13 | def test_simple_msg2(self): 14 | assert klm == 100, "This is wrong!" 15 | 16 | def test_type(self): 17 | # TODO: assert isinstance(100, list) 18 | # TODO: assert isinstance(klm, list) 19 | assert 100 == klm 20 | 21 | def test_type_msg(self): 22 | # TODO: assert isinstance(klm, tuple) 23 | # TODO: assert isinstance(100, tuple) 24 | assert klm == 100, "This is wrong!" 25 | 26 | def test_type_msg2(self): 27 | # TODO: assert isinstance(klm, list) 28 | # TODO: assert isinstance(100, list) 29 | assert klm == 100, "This is wrong!" 30 | 31 | def test_line_wrapping(self): 32 | assert [ 33 | 'a', 34 | 'b' 35 | ] == \ 36 | ['b'], \ 37 | "This is wrong!" 38 | 39 | assert 100 == klm 40 | -------------------------------------------------------------------------------- /.github/workflows/deploy.yml: -------------------------------------------------------------------------------- 1 | name: deploy 2 | 3 | on: 4 | workflow_dispatch: 5 | inputs: 6 | version: 7 | description: 'Release version' 8 | required: true 9 | default: '1.2.3' 10 | 11 | jobs: 12 | 13 | package: 14 | runs-on: ubuntu-latest 15 | 16 | steps: 17 | - uses: actions/checkout@v6 18 | 19 | - name: Build and Check Package 20 | uses: hynek/build-and-inspect-python-package@v2.14 21 | 22 | deploy: 23 | needs: package 24 | runs-on: ubuntu-latest 25 | permissions: 26 | id-token: write # For PyPI trusted publishers. 27 | contents: write # For tag. 28 | 29 | steps: 30 | - uses: actions/checkout@v6 31 | 32 | - name: Download Package 33 | uses: actions/download-artifact@v7 34 | with: 35 | name: Packages 36 | path: dist 37 | 38 | - name: Publish package to PyPI 39 | uses: pypa/gh-action-pypi-publish@v1.13.0 40 | with: 41 | attestations: true 42 | 43 | - name: GitHub Release 44 | env: 45 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} 46 | run: | 47 | gh release create v${{ github.event.inputs.version }} --target=${{ github.ref_name }} --title v${{ github.event.inputs.version }} 48 | gh pr merge ${{ github.ref_name }} --merge 49 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertAlmostEqual_in.py: -------------------------------------------------------------------------------- 1 | # required-method: assertAlmostEqual 2 | 3 | class TestAlmostAssertEqual(TestCase): 4 | def test_simple(self): 5 | self.assertAlmostEqual(100, klm) 6 | self.assertAlmostEqual(456, aaa and bbb) 7 | self.assertAlmostEqual(789, ccc or ddd) 8 | self.assertAlmostEqual(123, True if You else False) 9 | 10 | def test_simple_msg(self): 11 | self.assertAlmostEqual(klm, 100, msg="This is wrong!") 12 | 13 | def test_places(self): 14 | self.assertAlmostEqual(50+x, klm, 1) 15 | 16 | def test_places_msg(self): 17 | self.assertAlmostEqual(klm, 100, 1, msg=error_message) 18 | 19 | def test_places_kw(self): 20 | self.assertAlmostEqual(100, klm, places=1) 21 | 22 | def test_places_kw_msg(self): 23 | self.assertAlmostEqual(klm, 50+x, places=1, msg="This is wrong!") 24 | 25 | def test_places_kw_msg2(self): 26 | self.assertAlmostEqual(100, klm, msg=error_message, places=1) 27 | 28 | 29 | def test_delta_kw(self): 30 | self.assertAlmostEqual(klm, 100.01, delta=1) 31 | 32 | def test_delta_kw_msg(self): 33 | self.assertAlmostEqual(50+x, klm, delta=1, msg="This is wrong!") 34 | 35 | def test_delta_kw_msg2(self): 36 | self.assertAlmostEqual(klm, 100, msg=error_message, delta=1) 37 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertNotAlmostEqual_in.py: -------------------------------------------------------------------------------- 1 | # required-method: assertNotAlmostEqual 2 | 3 | class TestAssertNotAlmostEqual(TestCase): 4 | def test_simple(self): 5 | self.assertNotAlmostEqual(100, klm) 6 | self.assertNotAlmostEqual(456, aaa and bbb) 7 | self.assertNotAlmostEqual(789, ccc or ddd) 8 | self.assertNotAlmostEqual(123, True if You else False) 9 | 10 | def test_simple_msg(self): 11 | self.assertNotAlmostEqual(klm, 50+x, msg="This is wrong!") 12 | 13 | def test_places(self): 14 | self.assertNotAlmostEqual(100, klm, 1) 15 | 16 | def test_places_msg(self): 17 | self.assertNotAlmostEqual(klm, 100, 1, msg=error_message) 18 | 19 | def test_places_kw(self): 20 | self.assertNotAlmostEqual(50+x, klm, places=1) 21 | 22 | def test_places_kw_msg(self): 23 | self.assertNotAlmostEqual(klm, 100, places=1, msg="This is wrong!") 24 | 25 | def test_places_kw_msg2(self): 26 | self.assertNotAlmostEqual(100, klm, msg=error_message, places=1) 27 | 28 | 29 | def test_delta_kw(self): 30 | self.assertNotAlmostEqual(klm, 50+x, delta=1) 31 | 32 | def test_delta_kw_msg(self): 33 | self.assertNotAlmostEqual(100, klm, delta=1, msg="This is wrong!") 34 | 35 | def test_delta_kw_msg2(self): 36 | self.assertNotAlmostEqual(klm, 100, msg=error_message, delta=1) 37 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertEqual_in.py: -------------------------------------------------------------------------------- 1 | # required-method: assertEqual 2 | 3 | class TestAssertEqual(TestCase): 4 | def test_you(self): 5 | self.assertEqual(abc, 'xxx') 6 | self.assertEquals(abc, 'xxx') 7 | 8 | def test_me(self): 9 | self.assertEqual(123, xxx+y) 10 | self.assertEqual(456, aaa and bbb) 11 | self.assertEqual(789, ccc or ddd) 12 | self.assertEqual(123, True if You else False) 13 | 14 | def test_everybody(self): 15 | self.assertEqual( 'abc' , 'def' ) 16 | 17 | def test_message(self): 18 | self.assertEqual(123+z, xxx+y, msg='This is wrong!') 19 | self.assertEqual(123, xxx+y, 'This is wrong!') 20 | 21 | def test_line_wrapping(self): 22 | self.assertEqual(True, False, 'This will fail %s' % 23 | 'always') 24 | 25 | self.assertEqual( 26 | 27 | 'abc' 28 | .replace( 29 | 'abc' 30 | , 'def'), 31 | 'def', 32 | msg='Wrap %s' % 33 | 'everything') 34 | 35 | def test_expression_as_argument(self): 36 | self.assertEqual(abc not in self.data, True) 37 | self.assertEqual(abc in self.data, not contains) 38 | self.assertEqual(contains, not contains) 39 | -------------------------------------------------------------------------------- /RELEASING.rst: -------------------------------------------------------------------------------- 1 | ========================= 2 | Releasing unittest2pytest 3 | ========================= 4 | 5 | This document describes the steps to make a new ``unittest2pytest`` release. 6 | 7 | Version 8 | ------- 9 | 10 | ``main`` should always be green and a potential release candidate. ``unittest2pytest`` follows 11 | semantic versioning, so given that the current version is ``X.Y.Z``, to find the next version number 12 | one needs to look at the ``CHANGELOG.rst`` file: 13 | 14 | - If there any new feature, then we must make a new **minor** release: next 15 | release will be ``X.Y+1.0``. 16 | 17 | - Otherwise it is just a **bug fix** release: ``X.Y.Z+1``. 18 | 19 | 20 | Steps 21 | ----- 22 | 23 | To publish a new release ``X.Y.Z``, the steps are as follows: 24 | 25 | #. Create a new branch named ``release-X.Y.Z`` from the latest ``main``. 26 | 27 | #. Update the version in ``unittest2pytest/__init__.py``. 28 | 29 | #. Update the ``CHANGELOG.rst`` file with the new release information. 30 | 31 | #. Commit and push the branch to ``upstream`` and open a PR. 32 | 33 | #. Once the PR is **green** and **approved**, start the ``deploy`` workflow: 34 | 35 | .. code-block:: console 36 | 37 | gh workflow run deploy.yml -R pytest-dev/unittest2pytest --ref release-VERSION --field version=VERSION 38 | 39 | The PR will be automatically merged. 40 | 41 | #. Update the version in ``unittest2pytest/__init__.py`` and ``CHANGELOG.rst`` for the next release (usually use "minor+1" with the ``.dev0`` suffix). 42 | 43 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertSequenceEqual_in.py: -------------------------------------------------------------------------------- 1 | # required-method: assertSequenceEqual 2 | 3 | class TestSequenceEqual(TestCase): 4 | def test_simple(self): 5 | self.assertSequenceEqual(100, klm) 6 | self.assertSequenceEqual(456, aaa and bbb) 7 | self.assertSequenceEqual(789, ccc or ddd) 8 | self.assertSequenceEqual(123, True if You else False) 9 | 10 | def test_simple_msg(self): 11 | self.assertSequenceEqual(klm, 100, msg="This is wrong!") 12 | 13 | def test_simple_msg2(self): 14 | self.assertSequenceEqual(klm, 100, "This is wrong!") 15 | 16 | def test_type(self): 17 | # TODO: assert isinstance(100, list) 18 | # TODO: assert isinstance(klm, list) 19 | self.assertSequenceEqual(100, klm, seq_type=list) 20 | 21 | def test_type_msg(self): 22 | # TODO: assert isinstance(klm, tuple) 23 | # TODO: assert isinstance(100, tuple) 24 | self.assertSequenceEqual(klm, 100, seq_type=tuple, msg="This is wrong!") 25 | 26 | def test_type_msg2(self): 27 | # TODO: assert isinstance(klm, list) 28 | # TODO: assert isinstance(100, list) 29 | self.assertSequenceEqual(klm, 100, "This is wrong!", list) 30 | 31 | def test_line_wrapping(self): 32 | self.assertSequenceEqual( 33 | [ 34 | 'a', 35 | 'b' 36 | ], 37 | ['b'], 38 | "This is wrong!", 39 | list 40 | ) 41 | 42 | self.assertSequenceEqual(100, klm) 43 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertRaisesRegex_in.py: -------------------------------------------------------------------------------- 1 | # required-method: assertRaisesRegex 2 | 3 | class TestRaises(TestCase): 4 | def test_simple(self): 5 | self.assertRaisesRegex(RunTimeError, "text .* match", someFunc) 6 | 7 | def test_simple_with_newlines(self): 8 | self.assertRaisesRegex( 9 | RunTimeError, 10 | "text .* match", 11 | someFunc) 12 | 13 | def test_args(self): 14 | self.assertRaisesRegex(RunTimeError, "text .* match", someFunc, 1,2,3) 15 | 16 | def test_kwargs(self): 17 | self.assertRaisesRegex(RunTimeError, "text .* match", someFunc, foo=42, bar=43) 18 | 19 | def test_context_manager(self): 20 | with self.assertRaisesRegex(RunTimeError, "text .* match"): 21 | someFunc('foo', None) 22 | 23 | def test_args_kwargs(self): 24 | self.assertRaisesRegex(RunTimeError, "text .* match", someFunc, 1,2,3, foo=42, bar=43) 25 | 26 | def test_args_kwargs_with_newlines(self): 27 | # TODO: Newlines within arguments are not handled yet. 28 | self.assertRaisesRegex( 29 | RunTimeError, 30 | "text .* match", 31 | someFunc, 1, 32 | 2,3, 33 | foo=42, 34 | bar=43) 35 | 36 | def test_lambda(self): 37 | self.assertRaises(RunTimeError, lambda: error(1, 2)) 38 | self.assertRaises(RunTimeError, lambda: error(1, 2) or error()) 39 | 40 | def test_atom(self): 41 | self.assertRaisesRegex(RunTimeError, ("foo" "bar"), someFunc, 1,2,3) 42 | 43 | def test_expr(self): 44 | self.assertRaisesRegex(RunTimeError, "foo" + "bar", someFunc, 1,2,3) 45 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertRaisesRegexp_in.py: -------------------------------------------------------------------------------- 1 | # required-method: assertRaisesRegexp 2 | 3 | class TestRaises(TestCase): 4 | def test_simple(self): 5 | self.assertRaisesRegexp(RunTimeError, "text .* match", someFunc) 6 | 7 | def test_simple_with_newlines(self): 8 | self.assertRaisesRegexp( 9 | RunTimeError, 10 | "text .* match", 11 | someFunc) 12 | 13 | def test_args(self): 14 | self.assertRaisesRegexp(RunTimeError, "text .* match", someFunc, 1,2,3) 15 | 16 | def test_kwargs(self): 17 | self.assertRaisesRegexp(RunTimeError, "text .* match", someFunc, foo=42, bar=43) 18 | 19 | def test_context_manager(self): 20 | with self.assertRaisesRegexp(RunTimeError, "text .* match"): 21 | someFunc('foo', None) 22 | 23 | def test_args_kwargs(self): 24 | self.assertRaisesRegexp(RunTimeError, "text .* match", someFunc, 1,2,3, foo=42, bar=43) 25 | 26 | def test_args_kwargs_with_newlines(self): 27 | # TODO: Newlines within arguments are not handled yet. 28 | self.assertRaisesRegexp( 29 | RunTimeError, 30 | "text .* match", 31 | someFunc, 1, 32 | 2,3, 33 | foo=42, 34 | bar=43) 35 | 36 | def test_lambda(self): 37 | self.assertRaises(RunTimeError, lambda: error(1, 2)) 38 | self.assertRaises(RunTimeError, lambda: error(1, 2) or error()) 39 | 40 | def test_atom(self): 41 | self.assertRaisesRegexp(RunTimeError, ("foo" "bar"), someFunc, 1,2,3) 42 | 43 | def test_expr(self): 44 | self.assertRaisesRegexp(RunTimeError, "foo" + "bar", someFunc, 1,2,3) 45 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: Test 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | - "test-me-*" 8 | 9 | pull_request: 10 | branches: 11 | - "*" 12 | 13 | env: 14 | FORCE_COLOR: 1 15 | 16 | # Cancel running jobs for the same workflow and branch. 17 | concurrency: 18 | group: ${{ github.workflow }}-${{ github.ref }} 19 | cancel-in-progress: true 20 | 21 | jobs: 22 | package: 23 | runs-on: ubuntu-latest 24 | steps: 25 | - uses: actions/checkout@v6 26 | - name: Build and Check Package 27 | uses: hynek/build-and-inspect-python-package@v2.14 28 | 29 | test: 30 | needs: [package] 31 | runs-on: ${{ matrix.os }} 32 | strategy: 33 | fail-fast: false 34 | matrix: 35 | # Python >= 3.13 will fail with `ModuleNotFoundError: No module named 'lib2to3'` 36 | python-version: ["3.9", "3.10", "3.11", "3.12"] 37 | os: [ubuntu-latest, macos-latest] # , windows-latest] # Windows tests will fail. 38 | 39 | steps: 40 | - uses: actions/checkout@v6 41 | 42 | - name: Download Package 43 | uses: actions/download-artifact@v7 44 | with: 45 | name: Packages 46 | path: dist 47 | 48 | - name: Set up Python ${{ matrix.python-version }} 49 | uses: actions/setup-python@v6 50 | with: 51 | python-version: ${{ matrix.python-version }} 52 | 53 | - name: Install tox 54 | run: | 55 | python -m pip install --upgrade pip 56 | python -m pip install --upgrade tox 57 | 58 | - name: Test 59 | shell: bash 60 | run: | 61 | tox run -e py --installpkg `find dist/*.tar.gz` 62 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertRaisesRegex_out.py: -------------------------------------------------------------------------------- 1 | # required-method: assertRaisesRegex 2 | 3 | import pytest 4 | class TestRaises(TestCase): 5 | def test_simple(self): 6 | with pytest.raises(RunTimeError, match="text .* match"): 7 | someFunc() 8 | 9 | def test_simple_with_newlines(self): 10 | with pytest.raises(RunTimeError, match="text .* match"): 11 | someFunc() 12 | 13 | def test_args(self): 14 | with pytest.raises(RunTimeError, match="text .* match"): 15 | someFunc(1,2,3) 16 | 17 | def test_kwargs(self): 18 | with pytest.raises(RunTimeError, match="text .* match"): 19 | someFunc(foo=42, bar=43) 20 | 21 | def test_context_manager(self): 22 | with pytest.raises(RunTimeError, match="text .* match"): 23 | someFunc('foo', None) 24 | 25 | def test_args_kwargs(self): 26 | with pytest.raises(RunTimeError, match="text .* match"): 27 | someFunc(1,2,3, foo=42, bar=43) 28 | 29 | def test_args_kwargs_with_newlines(self): 30 | # TODO: Newlines within arguments are not handled yet. 31 | with pytest.raises(RunTimeError, match="text .* match"): 32 | someFunc(1, 33 | 2,3, 34 | foo=42, 35 | bar=43) 36 | 37 | def test_lambda(self): 38 | with pytest.raises(RunTimeError): 39 | error(1, 2) 40 | with pytest.raises(RunTimeError): 41 | error(1, 2) or error() 42 | 43 | def test_atom(self): 44 | with pytest.raises(RunTimeError, match=("foo" "bar")): 45 | someFunc(1,2,3) 46 | 47 | def test_expr(self): 48 | with pytest.raises(RunTimeError, match="foo" + "bar"): 49 | someFunc(1,2,3) 50 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertRaisesRegexp_out.py: -------------------------------------------------------------------------------- 1 | # required-method: assertRaisesRegexp 2 | 3 | import pytest 4 | class TestRaises(TestCase): 5 | def test_simple(self): 6 | with pytest.raises(RunTimeError, match="text .* match"): 7 | someFunc() 8 | 9 | def test_simple_with_newlines(self): 10 | with pytest.raises(RunTimeError, match="text .* match"): 11 | someFunc() 12 | 13 | def test_args(self): 14 | with pytest.raises(RunTimeError, match="text .* match"): 15 | someFunc(1,2,3) 16 | 17 | def test_kwargs(self): 18 | with pytest.raises(RunTimeError, match="text .* match"): 19 | someFunc(foo=42, bar=43) 20 | 21 | def test_context_manager(self): 22 | with pytest.raises(RunTimeError, match="text .* match"): 23 | someFunc('foo', None) 24 | 25 | def test_args_kwargs(self): 26 | with pytest.raises(RunTimeError, match="text .* match"): 27 | someFunc(1,2,3, foo=42, bar=43) 28 | 29 | def test_args_kwargs_with_newlines(self): 30 | # TODO: Newlines within arguments are not handled yet. 31 | with pytest.raises(RunTimeError, match="text .* match"): 32 | someFunc(1, 33 | 2,3, 34 | foo=42, 35 | bar=43) 36 | 37 | def test_lambda(self): 38 | with pytest.raises(RunTimeError): 39 | error(1, 2) 40 | with pytest.raises(RunTimeError): 41 | error(1, 2) or error() 42 | 43 | def test_atom(self): 44 | with pytest.raises(RunTimeError, match=("foo" "bar")): 45 | someFunc(1,2,3) 46 | 47 | def test_expr(self): 48 | with pytest.raises(RunTimeError, match="foo" + "bar"): 49 | someFunc(1,2,3) 50 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertRaises_in.py: -------------------------------------------------------------------------------- 1 | # required-method: assertRaises 2 | import os 3 | from os import listdir, path 4 | import subprocess as sb 5 | 6 | class Dummy(): 7 | pass 8 | 9 | class TestRaises(TestCase): 10 | def test_simple(self): 11 | import io 12 | from io import StringIO, BytesIO 13 | import numpy as np 14 | self.assertRaises(RunTimeError, someFunc) 15 | 16 | def test_simple_with_newlines(self): 17 | self.assertRaises( 18 | RunTimeError, 19 | someFunc) 20 | 21 | def test_args(self): 22 | self.assertRaises(RunTimeError, someFunc, 1,2,3) 23 | 24 | def test_kwargs(self): 25 | self.assertRaises(RunTimeError, someFunc, foo=42, bar=43) 26 | 27 | def test_args_kwargs(self): 28 | self.assertRaises(RunTimeError, someFunc, 1,2,3, foo=42, bar=43) 29 | 30 | def test_args_kwargs_with_newlines(self): 31 | # TODO: Newlines within arguments are not handled yet. 32 | self.assertRaises(RunTimeError, 33 | someFunc, 34 | 1,2, 35 | 3, 36 | foo=42, 37 | bar=43) 38 | 39 | def test_context_manager(self): 40 | with self.assertRaises(RunTimeError): 41 | someFunc() 42 | 43 | def test_context_manager_var(self): 44 | with self.assertRaises(RunTimeError) as ctx: 45 | someFunc() 46 | assert ctx.exception 47 | 48 | def test_lambda(self): 49 | self.assertRaises(RunTimeError, lambda: error(1, 2)) 50 | self.assertRaises(RunTimeError, lambda: error(1, 2) or error()) 51 | 52 | def test_kwargs(self): 53 | kwargs = {} 54 | self.assertRaises(RunTimeError, someFunc, **kwargs) 55 | -------------------------------------------------------------------------------- /tests/fixtures/self_assert/assertRaises_out.py: -------------------------------------------------------------------------------- 1 | # required-method: assertRaises 2 | import os 3 | from os import listdir, path 4 | import subprocess as sb 5 | import pytest 6 | 7 | class Dummy(): 8 | pass 9 | 10 | class TestRaises(TestCase): 11 | def test_simple(self): 12 | import io 13 | from io import StringIO, BytesIO 14 | import numpy as np 15 | with pytest.raises(RunTimeError): 16 | someFunc() 17 | 18 | def test_simple_with_newlines(self): 19 | with pytest.raises(RunTimeError): 20 | someFunc() 21 | 22 | def test_args(self): 23 | with pytest.raises(RunTimeError): 24 | someFunc(1,2,3) 25 | 26 | def test_kwargs(self): 27 | with pytest.raises(RunTimeError): 28 | someFunc(foo=42, bar=43) 29 | 30 | def test_args_kwargs(self): 31 | with pytest.raises(RunTimeError): 32 | someFunc(1,2,3, foo=42, bar=43) 33 | 34 | def test_args_kwargs_with_newlines(self): 35 | # TODO: Newlines within arguments are not handled yet. 36 | with pytest.raises(RunTimeError): 37 | someFunc(1,2, 38 | 3, 39 | foo=42, 40 | bar=43) 41 | 42 | def test_context_manager(self): 43 | with pytest.raises(RunTimeError): 44 | someFunc() 45 | 46 | def test_context_manager_var(self): 47 | with pytest.raises(RunTimeError) as ctx: 48 | someFunc() 49 | assert ctx.exception 50 | 51 | def test_lambda(self): 52 | with pytest.raises(RunTimeError): 53 | error(1, 2) 54 | with pytest.raises(RunTimeError): 55 | error(1, 2) or error() 56 | 57 | def test_kwargs(self): 58 | kwargs = {} 59 | with pytest.raises(RunTimeError): 60 | someFunc(**kwargs) 61 | -------------------------------------------------------------------------------- /unittest2pytest/utils.py: -------------------------------------------------------------------------------- 1 | """ 2 | Some utility functions for unittest2pytest. 3 | """ 4 | # 5 | # Copyright 2015-2019 by Hartmut Goebel 6 | # 7 | # This file is part of unittest2pytest. 8 | # 9 | # unittest2pytest is free software: you can redistribute it and/or modify 10 | # it under the terms of the GNU General Public License as published by 11 | # the Free Software Foundation, either version 3 of the License, or 12 | # (at your option) any later version. 13 | # 14 | # This program is distributed in the hope that it will be useful, but 15 | # WITHOUT ANY WARRANTY; without even the implied warranty of 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | # General Public License for more details. 18 | # 19 | # You should have received a copy of the GNU General Public License 20 | # along with this program. If not, see . 21 | # 22 | 23 | __author__ = "Hartmut Goebel " 24 | __copyright__ = "Copyright 2015-2019 by Hartmut Goebel" 25 | __licence__ = "GNU General Public License version 3 or later (GPLv3+)" 26 | 27 | 28 | import inspect 29 | from inspect import Parameter 30 | 31 | 32 | class SelfMarker: pass 33 | 34 | 35 | def resolve_func_args(test_func, posargs, kwargs): 36 | sig = inspect.signature(test_func) 37 | assert (list(iter(sig.parameters))[0] == 'self') 38 | posargs.insert(0, SelfMarker) 39 | ba = sig.bind(*posargs, **kwargs) 40 | ba.apply_defaults() 41 | args = ba.arguments 42 | required_args = [n for n,v in sig.parameters.items() 43 | if (v.default is Parameter.empty and 44 | v.kind not in (Parameter.VAR_POSITIONAL, Parameter.VAR_KEYWORD))] 45 | assert args['self'] == SelfMarker 46 | assert required_args[0] == 'self' 47 | del required_args[0], args['self'] 48 | required_args = [args[n] for n in required_args] 49 | 50 | return required_args, args 51 | -------------------------------------------------------------------------------- /CHANGELOG.rst: -------------------------------------------------------------------------------- 1 | Changelog 2 | ============ 3 | 4 | UNRELEASED 5 | ---------- 6 | 7 | *UNRELEASED* 8 | 9 | 10 | 0.5 11 | --- 12 | 13 | *2024-12-10* 14 | 15 | 16 | - Convert ``self.fail()`` to ``pytest.fail()`` (`#39`_). 17 | 18 | - Python >=3.9 is now required. 19 | 20 | - Allow non-string keys when translating ``assertDictContainsSubset`` (`#54`_). 21 | 22 | .. _#39: https://github.com/pytest-dev/unittest2pytest/issues/39 23 | .. _#54: https://github.com/pytest-dev/unittest2pytest/issues/54 24 | 25 | 26 | 27 | 0.4 (2019-06-30) 28 | ---------------- 29 | 30 | * Add support for ``assertDictContainsSubset``. 31 | 32 | * Put parenthesis around expressions if required. 33 | 34 | * Fixed assertRaisesRegex, assertRaisesRegexp and assertWarnsRegex. 35 | The regex was getting replaced with an undefined variable `pattern`. 36 | 37 | * Fix assertRaisesRegex and assertRaisesRegexp with `**kwargs` and 38 | `atom` parameters. 39 | 40 | * Made assertRaisesRegex, assertRaisesRegexp and assertWarnsRegex use 41 | the `match` kwarg in `pytest.raises` instead of creating a variable 42 | with the context manager and doing an assert on `re.search`. 43 | 44 | 45 | * Add a short developer guide. 46 | 47 | * Remove testing on Python 3.0, 3.1, 3.2, add 3.6 and 3.7. 48 | 49 | * Distribute package as a universal wheel. 50 | 51 | 52 | v0.3 (2016-07-26) 53 | ------------------ 54 | 55 | * Add support for assertRaises / assertWarns context managers. 56 | 57 | * Add support for converting lambda arguments in assertRaises into 58 | context managers. 59 | 60 | * Fix some incorrect transformations. 61 | 62 | * Internal cleanup and fixes. 63 | 64 | 65 | v0.2 (2015-10-20) 66 | --------------------- 67 | 68 | * Add support for assertRegex/assertRegexpMatches, assertNotRegex, 69 | assertRaisesRegex/assertRaisesRegexp, assertWarnsRegex. 70 | 71 | * `unittest2pytest` is now a `pytest` subproject. 72 | 73 | * Minor fixes. 74 | 75 | 76 | v0.1 (2015-10-16) 77 | --------------------- 78 | 79 | * Initial release 80 | 81 | .. 82 | Local Variables: 83 | mode: rst 84 | ispell-local-dictionary: "american" 85 | coding: utf-8 86 | End: 87 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright 2015-2019 by Hartmut Goebel 4 | # 5 | # This file is part of unittest2pytest. 6 | # 7 | # unittest2pytest is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, but 13 | # WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | # General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | # 20 | from pathlib import Path 21 | 22 | from setuptools import setup 23 | import re 24 | 25 | 26 | this_dir = Path(__file__).parent 27 | 28 | def get_version(filename): 29 | """ 30 | Return package version as listed in `__version__` in `filename`. 31 | """ 32 | init_py = this_dir.joinpath(filename).read_text(encoding="utf-8") 33 | return re.search("__version__ = ['\"]([^'\"]+)['\"]", init_py).group(1) 34 | 35 | 36 | version = get_version('unittest2pytest/__init__.py') 37 | 38 | 39 | def read(filename): 40 | return this_dir.joinpath(filename).read_text(encoding='utf-8') 41 | 42 | 43 | long_description = '\n\n'.join([read('README.rst'), 44 | read('CHANGELOG.rst')]) 45 | 46 | 47 | setup( 48 | name="unittest2pytest", 49 | license='GPLv3+', 50 | version=version, 51 | description="Convert unittest test-cases to pytest", 52 | long_description=long_description, 53 | long_description_content_type="text/x-rst", 54 | author="Hartmut Goebel", 55 | author_email="h.goebel@crazy-compilers.com", 56 | url="https://github.com/pytest-dev/unittest2pytest", 57 | packages=["unittest2pytest", "unittest2pytest.fixes"], 58 | entry_points={ 59 | 'console_scripts': [ 60 | 'unittest2pytest = unittest2pytest.__main__:main', 61 | ], 62 | }, 63 | classifiers=[ 64 | "Development Status :: 4 - Beta", 65 | "Environment :: Console", 66 | "Intended Audience :: Developers", 67 | "License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)", 68 | "Operating System :: OS Independent", 69 | "Programming Language :: Python", 70 | "Programming Language :: Python :: 3", 71 | "Programming Language :: Python :: 3 :: Only", 72 | "Programming Language :: Python :: 3.9", 73 | "Programming Language :: Python :: 3.10", 74 | "Programming Language :: Python :: 3.11", 75 | "Programming Language :: Python :: 3.12", 76 | "Topic :: Software Development", 77 | "Topic :: Utilities", 78 | ], 79 | python_requires=">=3.9", 80 | zip_safe=False 81 | ) 82 | -------------------------------------------------------------------------------- /unittest2pytest/fixes/fix_remove_class.py: -------------------------------------------------------------------------------- 1 | """ 2 | fix_remove_class - lib2to3 fix for removing "class Testxxx(TestCase):" 3 | headers and dedenting the contained code. 4 | """ 5 | # 6 | # Copyright 2015-2019 by Hartmut Goebel 7 | # 8 | # This file is part of unittest2pytest. 9 | # 10 | # unittest2pytest is free software: you can redistribute it and/or modify 11 | # it under the terms of the GNU General Public License as published by 12 | # the Free Software Foundation, either version 3 of the License, or 13 | # (at your option) any later version. 14 | # 15 | # This program is distributed in the hope that it will be useful, but 16 | # WITHOUT ANY WARRANTY; without even the implied warranty of 17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | # General Public License for more details. 19 | # 20 | # You should have received a copy of the GNU General Public License 21 | # along with this program. If not, see . 22 | # 23 | 24 | __author__ = "Hartmut Goebel " 25 | __copyright__ = "Copyright 2015-2019 by Hartmut Goebel" 26 | __licence__ = "GNU General Public License version 3 or later (GPLv3+)" 27 | 28 | 29 | from lib2to3.fixer_base import BaseFix 30 | from lib2to3.fixer_util import token, find_indentation 31 | 32 | """ 33 | Node(classdef, 34 | [Leaf(1, 'class'), 35 | Leaf(1, 'TestAssertEqual'), 36 | Leaf(7, '('), 37 | Leaf(1, 'TestCase'), 38 | Leaf(8, ')'), 39 | Leaf(11, ':'), 40 | Node(suite, [ 41 | Leaf(4, '\n'), 42 | Leaf(5, ' '), 43 | Node(funcdef, [ 44 | Leaf(1, 'def'), 45 | Leaf(1, 'test_you'), ... 46 | ]), 47 | Leaf(6, '')])]) 48 | """ 49 | 50 | class FixRemoveClass(BaseFix): 51 | 52 | PATTERN = """ 53 | classdef< 'class' name=any '(' 'TestCase' ')' ':' 54 | suite=suite 55 | > 56 | """ 57 | 58 | def dedent(self, suite, dedent): 59 | self.line_num = suite.get_lineno() 60 | for kid in suite.leaves(): 61 | if kid.type in (token.INDENT, token.DEDENT): 62 | self.line_num = kid.get_lineno() 63 | # todo: handle tabs 64 | kid.value = kid.value[dedent:] 65 | self.current_indent = kid.value 66 | elif kid.get_lineno() != self.line_num: 67 | # todo: handle tabs 68 | if len(kid.prefix) > len(self.current_indent): 69 | kid.prefix = self.current_indent 70 | 71 | 72 | def transform(self, node, results): 73 | suite = results['suite'].clone() 74 | # todo: handle tabs 75 | dedent = len(find_indentation(suite)) - len(find_indentation(node)) 76 | self.dedent(suite, dedent) 77 | 78 | # remove the first newline behind the classdef header 79 | first = suite.children[0] 80 | if first.type == token.NEWLINE: 81 | if len(first.value) == 1: 82 | del suite.children[0] 83 | else: 84 | first.value == first.value[1:] 85 | 86 | return suite 87 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | ================================== 2 | unittest2pytest 3 | ================================== 4 | 5 | ----------------------------------------------------- 6 | Helps converting unittest test-cases to pytest 7 | ----------------------------------------------------- 8 | 9 | :Author: Hartmut Goebel 10 | :Version: 0.5.dev0 11 | :Copyright: 2015 by Hartmut Goebel 12 | :Licence: GNU Public Licence v3 or later (GPLv3+) 13 | :Homepage: https://github.com/pytest-dev/unittest2pytest 14 | 15 | 16 | .. image:: https://github.com/pytest-dev/unittest2pytest/actions/workflows/test.yml/badge.svg 17 | :target: https://github.com/pytest-dev/unittest2pytest/actions 18 | :alt: See Build Status on GitHub Actions 19 | 20 | `unittest2pytest` is a tool that helps rewriting Python `unittest` 21 | test-cases into pytest_ test-cases. 22 | 23 | In contrast to other similar tools, this `unittest2pytest` 24 | 25 | * handles keyword arguments, 26 | * handles single-line test-cases and several tests on one line, 27 | * uses context-handlers where appropriate. 28 | 29 | This is done by using ``lib2to3`` (removed in Python >= 3.13) 30 | and Python's mighty ``inspect`` module. 31 | 32 | 33 | 34 | Installation 35 | =================== 36 | 37 | To install unittest2pytest, simply run:: 38 | 39 | uv tool install --python=3.12 unittest2pytest 40 | # Or to run once 41 | uv tool run --python=3.12 unittest2pytest . 42 | # Or shortcut to run once 43 | uvx --python=3.12 unittest2pytest . 44 | 45 | The ``--python=3.12`` ensures the presence of `lib2to3``. 46 | 47 | Usage 48 | =================== 49 | 50 | To print a diff of changes that unittest2pytest will make against a 51 | particular source file or directory:: 52 | 53 | unittest2pytest source_folder 54 | 55 | To have those changes written to the files:: 56 | 57 | unittest2pytest -w source_folder 58 | 59 | To have those changes written to another directory:: 60 | 61 | unittest2pytest -w source_folder --output-dir /some/where/else 62 | 63 | By default, this will create backup files for each file that will be 64 | changed. You can add the `-n` option to not create the backups. Please 65 | do not do this if you are not using a version control system. 66 | 67 | For more options about running particular fixers, run 68 | ``unittest2pytest --help`` or read the `lib2to3 documentation`_. This 69 | tool is built on top of that one. 70 | 71 | 72 | Fixes 73 | =================== 74 | 75 | A list of the available fixers can be found with the following:: 76 | 77 | $ unittest2pytest -l 78 | Available transformations for the -f/--fix option: 79 | remove_class 80 | self_assert 81 | 82 | 83 | Note: if your tests use the context managers ``with self.assertRaises`` or 84 | ``with self.assertWarns``, they will be transformed to ``pytest.raises`` or 85 | ``pytest.warns`` appropriately, but because the semantics are different, any 86 | use of the output value from the context managers (e.g., the ``x`` in 87 | ``with pytest.raises(ValueError) as x:``) will be wrong and will require 88 | manual adjustment after the fact. 89 | 90 | .. _`lib2to3 documentation`: http://docs.python.org/library/2to3.html 91 | .. _pytest: https://pytest.org/ 92 | 93 | 94 | .. 95 | Local Variables: 96 | mode: rst 97 | ispell-local-dictionary: "american" 98 | coding: utf-8 99 | End: 100 | -------------------------------------------------------------------------------- /tests/test_all_fixes.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | This file is part of test-suite for unittest2pytest. 4 | """ 5 | # 6 | # Copyright 2015-2019 by Hartmut Goebel 7 | # 8 | # This program is part of unittest2pytest. 9 | # 10 | # unittest2pytest free software: you can redistribute it and/or modify 11 | # it under the terms of the GNU General Public License as published by 12 | # the Free Software Foundation, either version 3 of the License, or 13 | # (at your option) any later version. 14 | # 15 | # This program is distributed in the hope that it will be useful, but 16 | # WITHOUT ANY WARRANTY; without even the implied warranty of 17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | # General Public License for more details. 19 | # 20 | # You should have received a copy of the GNU General Public License 21 | # along with this program. If not, see . 22 | # 23 | 24 | 25 | __author__ = "Hartmut Goebel " 26 | __copyright__ = "Copyright 2015-2019 by Hartmut Goebel" 27 | __licence__ = "GNU General Public License version 3 or later (GPLv3+)" 28 | 29 | 30 | import pytest 31 | 32 | 33 | import os 34 | from os.path import join, abspath 35 | import re 36 | import glob 37 | import shutil 38 | from difflib import unified_diff 39 | import unittest 40 | import logging 41 | 42 | from lib2to3.main import main 43 | 44 | # make logging less verbose 45 | logging.getLogger('lib2to3.main').setLevel(logging.WARN) 46 | logging.getLogger('RefactoringTool').setLevel(logging.WARN) 47 | 48 | FIXTURE_PATH = os.path.join(os.path.dirname(__file__), 'fixtures') 49 | 50 | def requiredTestMethod(name): 51 | # skip if TestCase does not have this method 52 | is_missing = getattr(unittest.TestCase, name, None) is None 53 | return pytest.mark.skipif(is_missing, 54 | reason="unittest does not have TestCase.%s " % name) 55 | 56 | 57 | def _collect_in_files_from_directory(directory): 58 | fixture_files = glob.glob(abspath(join(directory, '*_in.py'))) 59 | for fixture_file in fixture_files: 60 | with open(fixture_file) as fh: 61 | text = fh.read(200) 62 | l = re.findall(r'^# required-method: (\S+)', text) 63 | method = l[0] if l else None 64 | yield fixture_file, method 65 | 66 | 67 | def collect_all_test_fixtures(): 68 | for root, dirs, files in os.walk(FIXTURE_PATH): 69 | # Loop recursively through all files. If the files is in a 70 | # subdirectory, only run the fixer of the subdirectory name, else run 71 | # all fixers. 72 | for in_file, method in _collect_in_files_from_directory(root): 73 | fixer_to_run = root[len(FIXTURE_PATH)+1:] or None 74 | marks = [] 75 | if method: 76 | marks.append(requiredTestMethod(method)) 77 | yield pytest.param(fixer_to_run, in_file, marks=marks) 78 | 79 | 80 | def _get_id(argvalue): 81 | if argvalue is not None and argvalue.startswith(FIXTURE_PATH): 82 | return os.path.basename(argvalue).replace("_in.py", "") 83 | 84 | 85 | @pytest.mark.parametrize("fixer, in_file", 86 | collect_all_test_fixtures(), ids=_get_id) 87 | def test_check_fixture(in_file, fixer, tmpdir): 88 | if fixer: 89 | main("unittest2pytest.fixes", 90 | args=['--no-diffs', '--fix', fixer, '-w', in_file, 91 | '--nobackups', '--output-dir', str(tmpdir)]) 92 | else: 93 | main("unittest2pytest.fixes", 94 | args=['--no-diffs', '--fix', 'all', '-w', in_file, 95 | '--nobackups', '--output-dir', str(tmpdir)]) 96 | 97 | result_file_name = tmpdir.join(os.path.basename(in_file)) 98 | assert result_file_name.exists(), '%s is missing' % result_file_name 99 | result_file_contents = result_file_name.readlines() 100 | 101 | expected_file = in_file.replace("_in.py", "_out.py") 102 | with open(expected_file) as fh: 103 | expected_contents = fh.readlines() 104 | 105 | # ensure the expected code is actually correct and compiles 106 | try: 107 | compile(''.join(expected_contents), expected_file, 'exec') 108 | except Exception as e: 109 | pytest.fail(f"FATAL: {expected_file} does not compile: {e}", 110 | False) 111 | 112 | if result_file_contents != expected_contents: 113 | text = "Refactured code doesn't match expected outcome\n" 114 | text += ''.join(unified_diff(expected_contents, result_file_contents, 115 | 'expected', 'refactured result')) 116 | pytest.fail(text, False) 117 | -------------------------------------------------------------------------------- /unittest2pytest/fixes/fix_self_assert.py: -------------------------------------------------------------------------------- 1 | """ 2 | fix_self_assert - lib2to3 fix for replacing assertXXX() method calls 3 | by their pytest equivalent. 4 | """ 5 | # 6 | # Copyright 2015-2019 by Hartmut Goebel 7 | # 8 | # This file is part of unittest2pytest. 9 | # 10 | # unittest2pytest is free software: you can redistribute it and/or modify 11 | # it under the terms of the GNU General Public License as published by 12 | # the Free Software Foundation, either version 3 of the License, or 13 | # (at your option) any later version. 14 | # 15 | # This program is distributed in the hope that it will be useful, but 16 | # WITHOUT ANY WARRANTY; without even the implied warranty of 17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | # General Public License for more details. 19 | # 20 | # You should have received a copy of the GNU General Public License 21 | # along with this program. If not, see . 22 | # 23 | 24 | __author__ = "Hartmut Goebel " 25 | __copyright__ = "Copyright 2015-2019 by Hartmut Goebel" 26 | __licence__ = "GNU General Public License version 3 or later (GPLv3+)" 27 | 28 | 29 | from lib2to3.fixer_base import BaseFix 30 | from lib2to3.fixer_util import ( 31 | Comma, Name, Call, Node, Leaf, 32 | Newline, KeywordArg, find_indentation, 33 | ArgList, String, Number, syms, token, 34 | does_tree_import, is_import, parenthesize) 35 | 36 | from functools import partial 37 | import re 38 | import unittest 39 | 40 | from .. import utils 41 | 42 | 43 | TEMPLATE_PATTERN = re.compile('[\1\2]|[^\1\2]+') 44 | 45 | def CompOp(op, left, right, kws): 46 | op = Name(op, prefix=" ") 47 | left = parenthesize_expression(left) 48 | right = parenthesize_expression(right) 49 | 50 | left.prefix = "" 51 | if '\n' not in right.prefix: 52 | right.prefix = " " 53 | return Node(syms.comparison, (left, op, right), prefix=" ") 54 | 55 | 56 | def UnaryOp(prefix, postfix, value, kws): 57 | if prefix or postfix: 58 | value = parenthesize_expression(value) 59 | 60 | kids = [] 61 | if prefix: 62 | kids.append(Name(prefix, prefix=" ")) 63 | value.prefix = " " 64 | kids.append(value) 65 | if postfix: 66 | kids.append(Name(postfix, prefix=" ")) 67 | return Node(syms.test, kids, prefix=" ") 68 | 69 | 70 | # These symbols have lower precedence than the CompOps we use and thus 71 | # need to be parenthesized. For datails see 72 | # https://docs.python.org/3/reference/expressions.html#operator-precedence 73 | _NEEDS_PARENTHESIS = [ 74 | syms.test, # if – else 75 | syms.or_test, 76 | syms.and_test, 77 | syms.not_test, 78 | syms.comparison, 79 | ] 80 | 81 | def parenthesize_expression(value): 82 | if value.type in _NEEDS_PARENTHESIS: 83 | parenthesized = parenthesize(value.clone()) 84 | parenthesized.prefix = parenthesized.children[1].prefix 85 | parenthesized.children[1].prefix = '' 86 | value = parenthesized 87 | return value 88 | 89 | 90 | def fill_template(template, *args): 91 | parts = TEMPLATE_PATTERN.findall(template) 92 | kids = [] 93 | for p in parts: 94 | if p == '': 95 | continue 96 | elif p in '\1\2\3\4\5': 97 | p = args[ord(p)-1] 98 | p.prefix = '' 99 | else: 100 | p = Name(p) 101 | kids.append(p.clone()) 102 | return kids 103 | 104 | def DualOp(template, first, second, kws): 105 | kids = fill_template(template, first, second) 106 | return Node(syms.test, kids, prefix=" ") 107 | 108 | 109 | def SequenceEqual(left, right, kws): 110 | if 'seq_type' in kws: 111 | # :todo: implement `assert isinstance(xx, seq_type)` 112 | pass 113 | return CompOp('==', left, right, kws) 114 | 115 | 116 | def AlmostOp(places_op, delta_op, first, second, kws): 117 | first.prefix = "" 118 | second.prefix = "" 119 | first = parenthesize_expression(first) 120 | second = parenthesize_expression(second) 121 | abs_op = Call(Name('abs'), 122 | [Node(syms.factor, [first, Name('-'), second])]) 123 | if kws.get('delta', None) is not None: 124 | # delta 125 | return CompOp(delta_op, abs_op, kws['delta'], {}) 126 | else: 127 | # `7` is the default in unittest.TestCase.assertAlmostEqual 128 | places = kws['places'] or Number(7) 129 | places.prefix = " " 130 | round_op = Call(Name('round'), (abs_op, Comma(), places)) 131 | return CompOp(places_op, round_op, Number(0), {}) 132 | 133 | 134 | def RaisesOp(context, exceptionClass, indent, kws, arglist, node): 135 | exceptionClass.prefix = "" 136 | args = [exceptionClass] 137 | # Add match keyword arg to with statement if an expected regex was provided. 138 | if 'expected_regex' in kws: 139 | expected_regex = kws.get('expected_regex').clone() 140 | expected_regex.prefix = '' 141 | args.append(String(', ')) 142 | args.append( 143 | KeywordArg(Name('match'), expected_regex)) 144 | with_item = Call(Name(context), args) 145 | with_item.prefix = " " 146 | args = [] 147 | arglist = [a.clone() for a in arglist.children[4:]] 148 | if arglist: 149 | arglist[0].prefix="" 150 | 151 | func = None 152 | 153 | # :fixme: this uses hardcoded parameter names, which may change 154 | if 'callableObj' in kws: 155 | func = kws['callableObj'] 156 | elif 'callable_obj' in kws: 157 | func = kws['callable_obj'] 158 | elif kws['args']: # any arguments assigned to `*args` 159 | func = kws['args'][0] 160 | else: 161 | func = None 162 | 163 | if func is None: 164 | # Context manager 165 | return Node(syms.with_stmt, [with_item]) 166 | 167 | if func.type == syms.lambdef: 168 | suite = func.children[-1].clone() 169 | else: 170 | # TODO: Newlines within arguments are not handled yet. 171 | # If argument prefix contains a newline, all whitespace around this 172 | # ought to be replaced by indent plus 4+1+len(func) spaces. 173 | suite = Call(func, arglist) 174 | 175 | suite.prefix = indent + (4 * " ") 176 | return Node(syms.with_stmt, 177 | [Name('with'), 178 | with_item, 179 | Name(':'), 180 | Newline(), 181 | suite]) 182 | 183 | def RaisesRegexOp(context, designator, exceptionClass, expected_regex, 184 | indent, kws, arglist, node): 185 | arglist = [a.clone() for a in arglist.children] 186 | pattern = arglist[2] 187 | del arglist[2:4] # remove pattern and comma 188 | arglist = Node(syms.arglist, arglist) 189 | with_stmt = RaisesOp(context, exceptionClass, indent, kws, arglist, node) 190 | 191 | # if this is already part of a with statement we need to insert re.search 192 | # after the last leaf with content 193 | if node.parent.type == syms.with_stmt: 194 | parent_with = node.parent 195 | for leaf in reversed(list(parent_with.leaves())): 196 | if leaf.value.strip(): 197 | break 198 | i = leaf.parent.children.index(leaf) 199 | return with_stmt 200 | else: 201 | return Node(syms.suite, [with_stmt]) 202 | 203 | def FailOp(indent, kws, arglist, node): 204 | new = node.clone() 205 | new.set_child(0, Name('pytest')) 206 | return new 207 | 208 | def add_import(import_name, node): 209 | suite = get_parent_of_type(node, syms.suite) 210 | test_case = suite 211 | while test_case.parent.type != syms.file_input: 212 | test_case = test_case.parent 213 | file_input = test_case.parent 214 | 215 | if not does_tree_import(None, import_name, node): 216 | import_stmt = Node(syms.simple_stmt, 217 | [Node(syms.import_name, [Name('import'), Name(import_name, prefix=' ')]), 218 | Newline(), 219 | ]) 220 | insert_import(import_stmt, test_case, file_input) 221 | 222 | 223 | def get_parent_of_type(node, node_type): 224 | while node: 225 | if node.type == node_type: 226 | return node 227 | node = node.parent 228 | 229 | 230 | def insert_import(import_stmt, test_case, file_input): 231 | """This inserts an import in a very similar way as 232 | lib2to3.fixer_util.touch_import, but try to maintain encoding and shebang 233 | prefixes on top of the file when there is no import""" 234 | import_nodes = get_import_nodes(file_input) 235 | if import_nodes: 236 | last_import_stmt = import_nodes[-1].parent 237 | i = file_input.children.index(last_import_stmt) + 1 238 | # no import found, so add right before the test case 239 | else: 240 | i = file_input.children.index(test_case) 241 | import_stmt.prefix = test_case.prefix 242 | test_case.prefix = '' 243 | file_input.insert_child(i, import_stmt) 244 | 245 | 246 | def get_import_nodes(node): 247 | return [ 248 | x for c in node.children 249 | for x in c.children 250 | if c.type == syms.simple_stmt 251 | and is_import(x) 252 | ] 253 | 254 | 255 | _method_map = { 256 | # simple ones 257 | 'assertEqual': partial(CompOp, '=='), 258 | 'assertNotEqual': partial(CompOp, '!='), 259 | 'assertFalse': partial(UnaryOp, 'not', ''), 260 | 'assertGreater': partial(CompOp, '>'), 261 | 'assertGreaterEqual': partial(CompOp, '>='), 262 | 'assertIn': partial(CompOp, 'in'), 263 | 'assertIs': partial(CompOp, 'is'), 264 | 'assertIsInstance': partial(DualOp, 'isinstance(\1, \2)'), 265 | 'assertIsNone': partial(UnaryOp, '', 'is None'), 266 | 'assertIsNot': partial(CompOp, 'is not'), 267 | 'assertIsNotNone': partial(UnaryOp, '', 'is not None'), 268 | 'assertLess': partial(CompOp, '<'), 269 | 'assertLessEqual': partial(CompOp, '<='), 270 | 'assertNotIn': partial(CompOp, 'not in'), 271 | 'assertNotIsInstance': partial(DualOp, 'not isinstance(\1, \2)'), 272 | 'assertTrue': partial(UnaryOp, '', ''), 273 | 274 | # types ones 275 | 'assertDictEqual': partial(CompOp, '=='), 276 | 'assertListEqual': partial(CompOp, '=='), 277 | 'assertMultiLineEqual': partial(CompOp, '=='), 278 | 'assertSetEqual': partial(CompOp, '=='), 279 | 'assertTupleEqual': partial(CompOp, '=='), 280 | 'assertSequenceEqual': SequenceEqual, 281 | 282 | 'assertDictContainsSubset': partial(DualOp, '{**\2, **\1} == \2'), 283 | 'assertItemsEqual': partial(DualOp, 'sorted(\1) == sorted(\2)'), 284 | 285 | 'assertAlmostEqual': partial(AlmostOp, "==", "<"), 286 | 'assertNotAlmostEqual': partial(AlmostOp, "!=", ">"), 287 | 288 | 'assertRaises': partial(RaisesOp, 'pytest.raises'), 289 | 'assertWarns': partial(RaisesOp, 'pytest.warns'), # new Py 3.2 290 | 291 | 'assertRegex': partial(DualOp, 're.search(\2, \1)'), 292 | 'assertNotRegex': partial(DualOp, 'not re.search(\2, \1)'), # new Py 3.2 293 | 294 | 'assertRaisesRegex': partial(RaisesRegexOp, 'pytest.raises', 'excinfo'), 295 | 'assertWarnsRegex': partial(RaisesRegexOp, 'pytest.warns', 'record'), 296 | 297 | 'fail': FailOp, 298 | 299 | #'assertLogs': -- not to be handled here, is an context handler only 300 | } 301 | 302 | for newname, oldname in ( 303 | ('assertRaisesRegex', 'assertRaisesRegexp'), 304 | ('assertRegex', 'assertRegexpMatches'), 305 | ): 306 | if not hasattr(unittest.TestCase, newname): 307 | # use old name 308 | _method_map[oldname] = _method_map[newname] 309 | del _method_map[newname] 310 | 311 | for m in list(_method_map.keys()): 312 | if not hasattr(unittest.TestCase, m): 313 | del _method_map[m] 314 | 315 | 316 | # (Deprecated) Aliases 317 | _method_aliases = { 318 | 'assertEquals' : 'assertEqual', 319 | 'assertNotEquals' : 'assertNotEqual', 320 | 'assert_' : 'assertTrue', 321 | 'assertAlmostEquals' : 'assertAlmostEqual', 322 | 'assertNotAlmostEquals': 'assertNotAlmostEqual', 323 | 'assertRegexpMatches' : 'assertRegex', 324 | 'assertRaisesRegexp' : 'assertRaisesRegex', 325 | 326 | 'failUnlessEqual' : 'assertEqual', 327 | 'failIfEqual' : 'assertNotEqual', 328 | 'failUnless' : 'assertTrue', 329 | 'failIf' : 'assertFalse', 330 | 'failUnlessRaises' : 'assertRaises', 331 | 'failUnlessAlmostEqual': 'assertAlmostEqual', 332 | 'failIfAlmostEqual' : 'assertNotAlmostEqual', 333 | } 334 | 335 | for a, o in list(_method_aliases.items()): 336 | if not o in _method_map: 337 | # if the original name is not a TestCase method, remove the alias 338 | del _method_aliases[a] 339 | 340 | 341 | """ 342 | Node(power, 343 | [Leaf(1, u'self'), 344 | Node(trailer, 345 | [Leaf(23, u'.'), 346 | Leaf(1, u'assertEqual')]), 347 | Node(trailer, 348 | [Leaf(7, u'('), 349 | Node(arglist, 350 | [Leaf(1, u'abc'), 351 | Leaf(12, u','), 352 | Leaf(3, u"'xxx'")]), 353 | Leaf(8, u')')])]) 354 | 355 | Node(power, 356 | [Leaf(1, u'self'), 357 | Node(trailer, 358 | [Leaf(23, u'.'), 359 | Leaf(1, u'assertAlmostEqual')]), 360 | Node(trailer, 361 | [Leaf(7, u'('), 362 | Node(arglist, 363 | [Leaf(2, u'100'), 364 | Leaf(12, u','), 365 | Leaf(1, u'klm'), 366 | Leaf(12, u','), 367 | Node(argument, 368 | [Leaf(1, u'msg'), 369 | Leaf(22, u'='), 370 | Leaf(3, u'"Message"')]), 371 | Leaf(12, u','), 372 | Node(argument, 373 | [Leaf(1, u'places'), 374 | Leaf(22, u'='), 375 | Leaf(2, u'1')])]), 376 | Leaf(8, u')')])]) 377 | """ 378 | 379 | 380 | class FixSelfAssert(BaseFix): 381 | 382 | PATTERN = """ 383 | power< 'self' 384 | trailer< '.' method=( %s ) > 385 | trailer< '(' [arglist=any] ')' > 386 | > 387 | """ % ' | '.join(map(repr, 388 | (set(_method_map.keys()) | set(_method_aliases.keys())))) 389 | 390 | def transform(self, node, results): 391 | 392 | def process_arg(arg): 393 | if isinstance(arg, Leaf) and arg.type == token.COMMA: 394 | return 395 | elif (isinstance(arg, Node) and arg.type == syms.argument and 396 | arg.children[1].type == token.EQUAL): 397 | # keyword argument 398 | name, equal, value = arg.children 399 | assert name.type == token.NAME 400 | assert equal.type == token.EQUAL 401 | value = value.clone() 402 | kwargs[name.value] = value 403 | if '\n' in arg.prefix: 404 | value.prefix = arg.prefix 405 | else: 406 | value.prefix = arg.prefix.strip() + " " 407 | else: 408 | if (isinstance(arg, Node) and arg.type == syms.argument and 409 | arg.children[0].type == 36 and arg.children[0].value == '**'): 410 | return 411 | assert not kwargs, 'all positional args are assumed to come first' 412 | if (isinstance(arg, Node) and arg.type == syms.argument and 413 | arg.children[1].type == syms.comp_for): 414 | # argument is a generator expression w/o 415 | # parenthesis, add parenthesis 416 | value = arg.clone() 417 | value.children.insert(0, Leaf(token.LPAR, '(')) 418 | value.children.append(Leaf(token.RPAR, ')')) 419 | posargs.append(value) 420 | else: 421 | posargs.append(arg.clone()) 422 | 423 | method = results['method'][0].value 424 | # map (deprecated) aliases to original to avoid analysing 425 | # the decorator function 426 | method = _method_aliases.get(method, method) 427 | 428 | posargs = [] 429 | kwargs = {} 430 | 431 | # This is either empty, an "arglist", or a single argument 432 | if 'arglist' not in results: 433 | pass 434 | elif results['arglist'].type == syms.arglist: 435 | for arg in results['arglist'].children: 436 | process_arg(arg) 437 | else: 438 | process_arg(results['arglist']) 439 | 440 | try: 441 | test_func = getattr(unittest.TestCase, method) 442 | except AttributeError: 443 | raise RuntimeError("Your unittest package does not support '%s'. " 444 | "consider updating the package" % method) 445 | 446 | required_args, argsdict = utils.resolve_func_args(test_func, posargs, kwargs) 447 | 448 | if method.startswith(('assertRaises', 'assertWarns')) or method == 'fail': 449 | n_stmt = _method_map[method](*required_args, 450 | indent=find_indentation(node), 451 | kws=argsdict, 452 | arglist=results.get('arglist'), 453 | node=node) 454 | else: 455 | n_stmt = Node(syms.assert_stmt, 456 | [Name('assert'), 457 | _method_map[method](*required_args, kws=argsdict)]) 458 | if argsdict.get('msg', None) is not None and method != 'fail': 459 | n_stmt.children.extend((Name(','), argsdict['msg'])) 460 | 461 | def fix_line_wrapping(x): 462 | for c in x.children: 463 | # no need to worry about wrapping of "[", "{" and "(" 464 | if c.type in [token.LSQB, token.LBRACE, token.LPAR]: 465 | break 466 | if c.prefix.startswith('\n'): 467 | c.prefix = c.prefix.replace('\n', ' \\\n') 468 | fix_line_wrapping(c) 469 | fix_line_wrapping(n_stmt) 470 | # the prefix should be set only after fixing line wrapping because it can contain a '\n' 471 | n_stmt.prefix = node.prefix 472 | 473 | # add necessary imports 474 | if 'Raises' in method or 'Warns' in method or method == 'fail': 475 | add_import('pytest', node) 476 | if ('Regex' in method and not 'Raises' in method and 477 | not 'Warns' in method): 478 | add_import('re', node) 479 | 480 | return n_stmt 481 | -------------------------------------------------------------------------------- /COPYING-GPLv3.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------