Exemplo n.º 1
0
    def test_valid_python_identifier_for_valid(self):
        """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)
Exemplo n.º 2
0
    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))
Exemplo n.º 3
0
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))
Exemplo n.º 4
0
def test_valid_python_identifier_for_valid(value: str):
    assert asyncio.run(ValidPythonIdentifier.convert(None, value)) == value