Example #1
0
    def test_python_new_format_placeables(self):
        """Test detection of the new format string in python strings."""
        assert_equal(
            mark_placeables(u'Hello {name}'),
            u'Hello <mark class="placeable" title="Python format string">{name}</mark>'
        )

        assert_equal(
            mark_placeables(u'Hello {name!s}'),
            u'Hello <mark class="placeable" title="Python format string">{name!s}</mark>'
        )

        assert_equal(
            mark_placeables(u'Hello {someone.name}'),
            u'Hello <mark class="placeable" title="Python format string">{someone.name}</mark>'
        )

        assert_equal(
            mark_placeables(u'Hello {name[0]}'),
            u'Hello <mark class="placeable" title="Python format string">{name[0]}</mark>'
        )

        assert_equal(
            mark_placeables(u'Hello {someone.name[0]}'),
            u'Hello <mark class="placeable" title="Python format string">{someone.name[0]}</mark>'
        )
Example #2
0
def test_placeable_base_mark_newline_escape():
    """Test detecting newline escape sequences"""
    assert (mark_placeables(u'A string\\n') == (
        u'A string<mark class="placeable" '
        'title="Escaped newline">\\n</mark>'))
    assert (mark_placeables(u'\\nA string') == (
        u'<mark class="placeable" '
        'title="Escaped newline">\\n</mark>A string'))
    assert (mark_placeables(u'A\\nstring') == (
        u'A<mark class="placeable" '
        'title="Escaped newline">\\n</mark>string'))
    assert (mark_placeables(u'A string') == u'A string')
    assert (mark_placeables(u'A\nstring') == u'A\nstring')
Example #3
0
def test_placeable_base_format_named():
    """Test detection of format string with named placeables."""
    assert (mark_placeables(u'Hello %(name)s') == (
        u'Hello <mark class="placeable" '
        'title="Python format string">%(name)s</mark>'))
    assert (mark_placeables(u'Rolling %(number)d dices') == (
        u'Rolling <mark class="placeable" '
        'title="Python format string">%(number)d</mark> dices'))
    assert (mark_placeables(u'Hello %(name)S') == (
        u'Hello <mark class="placeable" '
        'title="Python format string">%(name)S</mark>'))
    assert (mark_placeables(u'Rolling %(number)D dices') == (
        u'Rolling <mark class="placeable" '
        'title="Python format string">%(number)D</mark> dices'))
Example #4
0
 def test_mark_newline_escape_placeables(self):
     """Test detecting newline escape sequences"""
     assert_equal(
         mark_placeables(u'A string\\n'),
         u'A string<mark class="placeable" title="Escaped newline">\\n</mark>'
     )
     assert_equal(
         mark_placeables(u'\\nA string'),
         u'<mark class="placeable" title="Escaped newline">\\n</mark>A string'
     )
     assert_equal(
         mark_placeables(u'A\\nstring'),
         u'A<mark class="placeable" title="Escaped newline">\\n</mark>string'
     )
     assert_equal(mark_placeables(u'A string'), u'A string')
     assert_equal(mark_placeables(u'A\nstring'), u'A\nstring')
Example #5
0
def test_placeable_base_python_new_format():
    """Test detection of the new format string in python strings."""
    assert (mark_placeables(u'Hello {name}') == (
        u'Hello <mark class="placeable" '
        'title="Python format string">{name}</mark>'))
    assert (mark_placeables(u'Hello {name!s}') == (
        u'Hello <mark class="placeable" '
        'title="Python format string">{name!s}</mark>'))
    assert (mark_placeables(u'Hello {someone.name}') == (
        u'Hello <mark class="placeable" '
        'title="Python format string">{someone.name}</mark>'))
    assert (mark_placeables(u'Hello {name[0]}') == (
        u'Hello <mark class="placeable" '
        'title="Python format string">{name[0]}</mark>'))
    assert (mark_placeables(u'Hello {someone.name[0]}') == (
        u'Hello <mark class="placeable" '
        'title="Python format string">{someone.name[0]}</mark>'))
Example #6
0
def test_placeable_base_format_named():
    """Test detection of format string with named placeables."""
    assert (
        mark_placeables(u'Hello %(name)s')
        == (u'Hello <mark class="placeable" '
            'title="Python format string">%(name)s</mark>'))
    assert (
        mark_placeables(u'Rolling %(number)d dices')
        == (u'Rolling <mark class="placeable" '
            'title="Python format string">%(number)d</mark> dices'))
    assert (
        mark_placeables(u'Hello %(name)S')
        == (u'Hello <mark class="placeable" '
            'title="Python format string">%(name)S</mark>'))
    assert (
        mark_placeables(u'Rolling %(number)D dices')
        == (u'Rolling <mark class="placeable" '
            'title="Python format string">%(number)D</mark> dices'))
Example #7
0
def test_placeable_base_mark_newline_escape():
    """Test detecting newline escape sequences"""
    assert (
        mark_placeables(u'A string\\n')
        == (u'A string<mark class="placeable" '
            'title="Escaped newline">\\n</mark>'))
    assert (
        mark_placeables(u'\\nA string')
        == (u'<mark class="placeable" '
            'title="Escaped newline">\\n</mark>A string'))
    assert (
        mark_placeables(u'A\\nstring')
        == (u'A<mark class="placeable" '
            'title="Escaped newline">\\n</mark>string'))
    assert (
        mark_placeables(u'A string')
        == u'A string')
    assert (
        mark_placeables(u'A\nstring')
        == u'A\nstring')
Example #8
0
    def serialize(self):
        try:
            source = eval(self.source)
        except SyntaxError:
            source = self.source

        return {
            'pk': self.pk,
            'original': self.string,
            'marked': utils.mark_placeables(self.string),
            'original_plural': self.string_plural,
            'marked_plural': utils.mark_placeables(self.string_plural),
            'key': self.key,
            'path': self.resource.path,
            'format': self.resource.format,
            'comment': self.comment,
            'order': self.order,
            'source': source,
            'obsolete': self.obsolete,
        }
Example #9
0
    def test_python_format_named_placeables(self):
        """Test detection of format string with named placeables."""
        assert_equal(
            mark_placeables(u'Hello %(name)s'),
            u'Hello <mark class="placeable" title="Python format string">%(name)s</mark>'
        )

        assert_equal(
            mark_placeables(u'Rolling %(number)d dices'),
            u'Rolling <mark class="placeable" title="Python format string">%(number)d</mark> dices'
        )

        assert_equal(
            mark_placeables(u'Hello %(name)S'),
            u'Hello <mark class="placeable" title="Python format string">%(name)S</mark>'
        )

        assert_equal(
            mark_placeables(u'Rolling %(number)D dices'),
            u'Rolling <mark class="placeable" title="Python format string">%(number)D</mark> dices'
        )
Example #10
0
def test_placeable_json_placeholder():
    """Test detection of JSON placeholders."""
    assert (
        mark_placeables(u'Hello $USER$')
        == (u'Hello <mark class="placeable" '
            'title="JSON placeholder">$USER$</mark>'))

    assert (
        mark_placeables(u'Hello $USER1$')
        == (u'Hello <mark class="placeable" '
            'title="JSON placeholder">$USER1$</mark>'))

    assert (
        mark_placeables(u'Hello $FIRST_NAME$')
        == (u'Hello <mark class="placeable" '
            'title="JSON placeholder">$FIRST_NAME$</mark>'))

    assert (
        mark_placeables(u'Hello $user$')
        == (u'Hello $user$'))

    assert (
        mark_placeables(u'Hello $USER')
        == (u'Hello $<mark class="placeable" '
            'title="Long all-caps string">USER</mark>'))

    assert (
        mark_placeables(u'Hello USER$')
        == (u'Hello <mark class="placeable" '
            'title="Long all-caps string">USER</mark>$'))
Example #11
0
def test_placeable_base_python_new_format():
    """Test detection of the new format string in python strings."""
    assert (
        mark_placeables(u'Hello {name}')
        == (u'Hello <mark class="placeable" '
            'title="Python format string">{name}</mark>'))
    assert (
        mark_placeables(u'Hello {name!s}')
        == (u'Hello <mark class="placeable" '
            'title="Python format string">{name!s}</mark>'))
    assert (
        mark_placeables(u'Hello {someone.name}')
        == (u'Hello <mark class="placeable" '
            'title="Python format string">{someone.name}</mark>'))
    assert (
        mark_placeables(u'Hello {name[0]}')
        == (u'Hello <mark class="placeable" '
            'title="Python format string">{name[0]}</mark>'))
    assert (
        mark_placeables(u'Hello {someone.name[0]}')
        == (u'Hello <mark class="placeable" '
            'title="Python format string">{someone.name[0]}</mark>'))
Example #12
0
 def test_mark_newline_escape_placeables(self):
     """Test detecting newline escape sequences"""
     assert_equal(
         mark_placeables(u'A string\\n'),
         u'A string<mark class="placeable" title="Escaped newline">\\n</mark>'
     )
     assert_equal(
         mark_placeables(u'\\nA string'),
         u'<mark class="placeable" title="Escaped newline">\\n</mark>A string'
     )
     assert_equal(
         mark_placeables(u'A\\nstring'),
         u'A<mark class="placeable" title="Escaped newline">\\n</mark>string'
     )
     assert_equal(
         mark_placeables(u'A string'),
         u'A string'
     )
     assert_equal(
         mark_placeables(u'A\nstring'),
         u'A\nstring'
     )
Example #13
0
def test_placeable_json_placeholder():
    """Test detection of JSON placeholders."""
    assert (mark_placeables(u'Hello $USER$') == (
        u'Hello <mark class="placeable" '
        'title="JSON placeholder">$USER$</mark>'))

    assert (mark_placeables(u'Hello $USER1$') == (
        u'Hello <mark class="placeable" '
        'title="JSON placeholder">$USER1$</mark>'))

    assert (mark_placeables(u'Hello $FIRST_NAME$') == (
        u'Hello <mark class="placeable" '
        'title="JSON placeholder">$FIRST_NAME$</mark>'))

    assert (mark_placeables(u'Hello $user$') == (u'Hello $user$'))

    assert (mark_placeables(u'Hello $USER') == (
        u'Hello $<mark class="placeable" '
        'title="Long all-caps string">USER</mark>'))

    assert (mark_placeables(u'Hello USER$') == (
        u'Hello <mark class="placeable" '
        'title="Long all-caps string">USER</mark>$'))
Example #14
0
 def marked_plural(self):
     return utils.mark_placeables(self.string_plural)
Example #15
0
 def marked(self):
     return utils.mark_placeables(self.string)
Example #16
0
 def marked(self):
     return utils.mark_placeables(self.string)
Example #17
0
 def marked_plural(self):
     return utils.mark_placeables(self.string_plural)