def test_cannot_register_placeholders_with_incorrect_parent_classes(self):
     # Setup
     number_of_placeholders_before = len(placeholder_pool.get_placeholders())
     # Run & check
     with pytest.raises(ImproperlyConfigured):
         class ErrnoneousPlaceholder:
             pass
         placeholder_pool.register_placeholder(ErrnoneousPlaceholder)
     number_of_placeholders_after = len(placeholder_pool.get_placeholders())
     assert number_of_placeholders_before == number_of_placeholders_after
 def test_should_raise_if_a_placeholder_is_registered_twice(self):
     # Setup
     number_of_placeholders_before = len(placeholder_pool.get_placeholders())
     placeholder_pool.register_placeholder(FooPlaceholder)
     # Run & check
     # Let's add it a second time. We should catch an exception
     with pytest.raises(PlaceholderAlreadyRegistered):
         placeholder_pool.register_placeholder(FooPlaceholder)
     # Let's make sure we have the same number of tags as before
     placeholder_pool.unregister_placeholder(FooPlaceholder)
     number_of_placeholders_after = len(placeholder_pool.get_placeholders())
     assert number_of_placeholders_before == number_of_placeholders_after
 def test_placeholders_can_be_used_with_tags(self):
     # Setup
     parser_loader = BBCodeParserLoader(parser=self.parser)
     placeholder_pool.register_placeholder(FooPlaceholder)
     placeholder_pool.register_placeholder(DummyPlaceholder)
     tag_pool.register_tag(FooBBCodeTag)
     tag_pool.register_tag(DummyBBCodeTag)
     parser_loader.init_bbcode_placeholders()
     parser_loader.init_bbcode_tags()
     # Run & check
     for bbcodes_text, expected_html_text in self.TAGS_TESTS:
         result = self.parser.render(bbcodes_text)
         assert result == expected_html_text
     placeholder_pool.unregister_placeholder(FooPlaceholder)
     placeholder_pool.unregister_placeholder(DummyPlaceholder)
# -*- coding: utf-8 -*-

# Standard library imports
import re

# Third party imports
from precise_bbcode.bbcode.placeholder import BBCodePlaceholder
from precise_bbcode.placeholder_pool import placeholder_pool

# Local application / specific library imports


class PhoneNumberBBCodePlaceholder(BBCodePlaceholder):
    name = 'phonenumber'
    pattern = re.compile(r'(\d{3}[-\.\s]??\d{3}[-\.\s]??\d{4}|\(\d{3}\)\s*\d{3}[-\.\s]??\d{4}|\d{3}[-\.\s]??\d{4})')


class StartsWithBBCodePlaceholder(BBCodePlaceholder):
    name = 'startswith'

    def validate(self, content, extra_context):
        return content.startswith(extra_context)


placeholder_pool.register_placeholder(PhoneNumberBBCodePlaceholder)
placeholder_pool.register_placeholder(StartsWithBBCodePlaceholder)