Ejemplo n.º 1
0
    def test_tag_name_converter_for_valid(self):
        """TagNameConverter should return the correct values for valid tag names."""
        test_values = (
            ('tracebacks', 'tracebacks'),
            ('Tracebacks', 'tracebacks'),
            ('  Tracebacks  ', 'tracebacks'),
        )

        for name, expected_conversion in test_values:
            with self.subTest(name=name, expected_conversion=expected_conversion):
                conversion = asyncio.run(TagNameConverter.convert(self.context, name))
                self.assertEqual(conversion, expected_conversion)
Ejemplo n.º 2
0
    def test_tag_name_converter_for_invalid(self):
        """TagNameConverter should raise the correct exception for invalid tag names."""
        test_values = (
            ('👋', "Don't be ridiculous, you can't use that character!"),
            ('', "Tag names should not be empty, or filled with whitespace."),
            ('  ', "Tag names should not be empty, or filled with whitespace."),
            ('42', "Tag names can't be numbers."),
            ('x' * 128, "Are you insane? That's way too long!"),
        )

        for invalid_name, exception_message in test_values:
            with self.subTest(invalid_name=invalid_name, exception_message=exception_message):
                with self.assertRaises(BadArgument, msg=exception_message):
                    asyncio.run(TagNameConverter.convert(self.context, invalid_name))
Ejemplo n.º 3
0
def test_tag_name_converter_for_invalid(value: str, expected: str):
    context = MagicMock()
    context.author = 'bob'

    with pytest.raises(BadArgument, match=expected):
        asyncio.run(TagNameConverter.convert(context, value))
Ejemplo n.º 4
0
def test_tag_name_converter_for_valid(value: str, expected: str):
    assert asyncio.run(TagNameConverter.convert(None, value)) == expected