def test_valid_python_identifier_for_valid(self): """Tests if ValidPythonIdentifier returns valid identifiers unchanged.""" test_values = ('foo', 'lemon') for name in test_values: with self.subTest(identifier=name): conversion = asyncio.run( ValidPythonIdentifier.convert(self.context, name)) self.assertEqual(name, conversion)
def test_valid_python_identifier_for_invalid(self): """ValidPythonIdentifier raises the proper exception for invalid identifiers.""" test_values = ('nested.stuff', '#####') for name in test_values: with self.subTest(identifier=name): exception_message = f'`{name}` is not a valid Python identifier' with self.assertRaises(BadArgument, msg=exception_message): asyncio.run(ValidPythonIdentifier.convert(self.context, name))
def test_valid_python_identifier_for_invalid(value: str): with pytest.raises(BadArgument, match=f'`{value}` is not a valid Python identifier'): asyncio.run(ValidPythonIdentifier.convert(None, value))
def test_valid_python_identifier_for_valid(value: str): assert asyncio.run(ValidPythonIdentifier.convert(None, value)) == value