Beispiel #1
0
    def test_write_many_msgs(self):
        expected = [
            '\n',
            '#: ../path/to/file.js:10',
            'msgid "Fox"',
            'msgstr "Лиса"',
            '\n',
            '#: ../path/to/file.js:300',
            'msgid "Box"',
            'msgid_plural "Boxes"',
            'msgstr[0] "Ящик"',
            'msgstr[1] "Ящика"',
        ]
        msg_collection = MsgCollection()
        msg_collection.add_msg(id='Fox',
                               str='Лиса',
                               paths=['../path/to/file.js:10'])
        msg_collection.add_msg_plural(id='Box',
                                      id_plural='Boxes',
                                      strs=['Ящик', 'Ящика'],
                                      paths=['../path/to/file.js:300'])

        result = self.writer.write_lines(msg_collection)

        self.assertEqual(expected, result)
Beispiel #2
0
    def test_parse_single_and_plurals(self):
        expected = MsgCollection()
        expected.add_msg(id='Fox', str='Лиса', paths=['../path/to/file.js:10'])
        expected.add_msg_plural(id='Box', id_plural='Boxes', strs=['Ящик', 'Ящика'], paths=['../path/to/file.js:300'])
        lines = [
            'TRASH',

            '\n',
            '#: ../path/to/file.js:10',
            'msgid "Fox"',
            'msgstr "Лиса"',

            '\n',
            '#: ../path/to/file.js:300',
            'msgid "Box"',
            'msgid_plural "Boxes"',
            'msgstr[0] "Ящик"',
            'msgstr[1] "Ящика"',

            'TRASH',

        ]

        result = self.parser.parse_lines(lines)

        self.assertEqual(expected, result)
Beispiel #3
0
    def test_put_and_get_plural_msg(self):
        expected = ['Ящик', 'Ящики']
        msg_collection = MsgCollection()
        msg_collection.add_msg_plural(id='Box',
                                      id_plural='Boxes',
                                      strs=['Ящик', 'Ящики'])

        result = msg_collection.get_msg('Box').strs

        self.assertEqual(expected, result)
Beispiel #4
0
    def test_len(self):
        expected = 2
        msg_collection = MsgCollection()
        msg_collection.add_msg(id='Fox', str='Лиса')
        msg_collection.add_msg_plural(id='Box',
                                      id_plural='Boxes',
                                      strs=['Ящик', 'Ящики'])

        result = len(msg_collection)

        self.assertEqual(expected, result)
Beispiel #5
0
def get_ru_expected_collection():
    result = MsgCollection()
    result.add_msg(
        id='Cake',
        str='Кекс',
        paths=['../modules/user/x.js:112', '../modules/user/x.js:300'])
    result.add_msg_plural(
        id='Cookie',
        id_plural='Cookies',
        strs=['Печенька', 'Печеньки'],
        paths=['../modules/user/x.js:112', '../modules/user/x.js:300'])
    return result
Beispiel #6
0
 def execute(self, line, msg_collection: MsgCollection):
     msgid_plural = line.split('msgid_plural')[1].strip().strip('"')
     if msg_collection.current_msg:
         current_id = msg_collection.current_msg.id
         current_paths = msg_collection.current_msg.paths
         msg_collection.remove_msg(current_id)
         msg_collection.add_msg_plural(id=current_id,
                                       id_plural=msgid_plural,
                                       strs=[],
                                       paths=current_paths)
         msg_collection.current_msg = msg_collection.get_msg(id=current_id)
         return
     raise ValueError()
Beispiel #7
0
    def test_write_plural_0(self):
        expected = [
            '\n', '#: ../path/to/file.js:300', 'msgid "Box"',
            'msgid_plural "Boxes"', 'msgstr[0] "Ящик"'
        ]
        msg_collection = MsgCollection()
        msg_collection.add_msg_plural(id='Box',
                                      id_plural='Boxes',
                                      strs=['Ящик'],
                                      paths=['../path/to/file.js:300'])

        result = self.writer.write_lines(msg_collection)

        self.assertEqual(expected, result)
Beispiel #8
0
    def test_simple_iter(self):
        expected = [
            Msg(id='Fox', str='Лиса'),
            MsgPlural(id='Box', id_plural='Boxes', strs=['Ящик', 'Ящики'])
        ]
        msg_collection = MsgCollection()
        msg_collection.add_msg(id='Fox', str='Лиса')
        msg_collection.add_msg_plural(id='Box',
                                      id_plural='Boxes',
                                      strs=['Ящик', 'Ящики'])

        result = [msg for msg in msg_collection]

        self.assertEqual(expected, result)
Beispiel #9
0
    def test_parse_plural_0(self):
        expected = MsgCollection()
        expected.add_msg_plural(id='Box', id_plural='Boxes', strs=['Ящик'], paths=['../path/to/file.js:300'])
        lines = [
            'TRASH',

            '\n',
            '#: ../path/to/file.js:300',
            'msgid "Box"',
            'msgid_plural "Boxes"',
            'msgstr[0] "Ящик"'
        ]

        result = self.parser.parse_lines(lines)

        self.assertEqual(expected, result)
    def test_write_file_parse_file_(self):
        msg_collection = MsgCollection()
        msg_collection.add_msg(id='Fax', str='Факс', paths=[
            '../path.js:12'
        ])
        msg_collection.add_msg_plural(id='Box', id_plural='Boxes', strs=[
            'Ящик', 'Ящика'
        ], paths=[
            '../path.js:20'
        ])
        msg_collection.add_msg_plural(id='Fox', id_plural='Foxes', strs=[
            'Лиса', 'Лис'
        ], paths=[
            '../path.js:30'
        ])

        PoWriter.new().write_file(path, msg_collection)
        parsed_msg_collection = PoParser.new().parse_file(path)

        self.assertEqual(msg_collection, parsed_msg_collection)