Ejemplo n.º 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)
Ejemplo n.º 2
0
    def test_has_msg(self):
        msg_collection = MsgCollection()
        msg_collection.add_msg(id='Box')

        result = msg_collection.has_msg('Box')

        self.assertTrue(result)
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
    def test_count(self):
        expected = 1
        msg_collection = MsgCollection()
        msg_collection.add_msg(id='Box', str='Ящик')

        result = msg_collection.count

        self.assertEqual(expected, result)
Ejemplo n.º 5
0
    def test_put_and_get_single_msg(self):
        expected = 'Ящик'
        msg_collection = MsgCollection()
        msg_collection.add_msg(id='Box', str='Ящик')

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

        self.assertEqual(expected, result)
Ejemplo n.º 6
0
    def test_eq(self):
        msg_collection1 = MsgCollection()
        msg_collection1.add_msg(id='Box', str='Ящик')

        msg_collection2 = MsgCollection()
        msg_collection2.add_msg(id='Box', str='Ящик')

        self.assertEqual(msg_collection1, msg_collection2)
Ejemplo n.º 7
0
    def test_iter(self):
        box = Msg(id='Box')
        box.str = 'Ящик'
        expected = [box]
        msg_collection = MsgCollection()
        msg_collection.add_msg(id='Box', str='Ящик')

        result = [msg for msg in msg_collection.msgs]

        self.assertEqual(expected, result)
Ejemplo n.º 8
0
    def test_add_str_to(self):
        expected = Msg(id='Box', str='Коробка')

        msg_collection = MsgCollection()
        msg_collection.add_msg(id='Box', str='Ящик')
        msg_collection.add_str_to(id='Box', str='Коробка')

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

        self.assertEqual(expected, result)
Ejemplo n.º 9
0
    def test_remove_msg(self):
        expected = MsgCollection()

        msg_collection = MsgCollection()
        msg_collection.add_msg(id='Box', str='Ящик')
        msg_collection.remove_msg(id='Box')

        result = msg_collection

        self.assertEqual(expected, result)
Ejemplo n.º 10
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)
Ejemplo n.º 11
0
    def test_parse_path_line(self):
        expected = MsgCollection()
        expected.add_msg(id='Current', str='', paths=['../path/to/file.js:300'])
        lines = [
            '\n',
            '#: ../path/to/file.js:300'
        ]

        result = self.parser.parse_lines(lines)

        self.assertEqual(expected, result)
Ejemplo n.º 12
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
Ejemplo n.º 13
0
    def test_add_msg_with_paths(self):
        expected = ['../modules/user/x.js:112', '../modules/user/x.js:300']
        msg_collection = MsgCollection()
        msg_collection.add_msg(
            id='Box',
            str='Ящик',
            paths=['../modules/user/x.js:112', '../modules/user/x.js:300'])

        box = msg_collection.get_msg('Box')
        result = [p for p in box.paths]

        self.assertEqual(expected, result)
Ejemplo n.º 14
0
    def test_parse_str_line(self):
        expected = MsgCollection()
        expected.add_msg(id='Box', str='Ящик', paths=['../path/to/file.js:300'])
        lines = [
            '\n',
            '#: ../path/to/file.js:300',
            'msgid "Box"',
            'msgstr "Ящик"'
        ]

        result = self.parser.parse_lines(lines)

        self.assertEqual(expected, result)
Ejemplo n.º 15
0
    def test_execute(self):
        expected = MsgCollection()
        expected.add_msg(
            id='Current',
            str='',
            paths=['../modules/user/x.js:300', '../modules/user/x.js:500'])
        command = ParseMsgPath('parse_path')
        line = '#: ../modules/user/x.js:300 ../modules/user/x.js:500'

        result = MsgCollection()
        command.execute(line, result)

        self.assertEqual(expected, result)
Ejemplo n.º 16
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)
Ejemplo n.º 17
0
    def test_add_path_to(self):
        expected = Msg(
            id='Box',
            str='Ящик',
            paths=['../modules/user/x.js:112', '../modules/user/x.js:300'])

        msg_collection = MsgCollection()
        msg_collection.add_msg(id='Box', str='Ящик')
        msg_collection.add_path_to(id='Box', path='../modules/user/x.js:112')
        msg_collection.add_path_to(id='Box', path='../modules/user/x.js:300')

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

        self.assertEqual(expected, result)
Ejemplo n.º 18
0
    def test_write_path_line(self):
        expected = [
            '\n',
            '#: ../path/to/file.js:300',
            'msgid "Box"',
            'msgstr "Ящик"',
        ]
        msg_collection = MsgCollection()
        msg_collection.add_msg(id='Box',
                               str='Ящик',
                               paths=['../path/to/file.js:300'])

        result = self.writer.write_lines(msg_collection)

        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)