Ejemplo n.º 1
0
    def test_create_current_msg(self):
        msg_collection = MsgCollection()
        msg_collection.create_current_msg()

        result = msg_collection.current_msg

        self.assertIsNotNone(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_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.º 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_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.º 6
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)
Ejemplo n.º 7
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.º 8
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.º 9
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.º 10
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.º 11
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)
Ejemplo n.º 12
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.º 13
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)
Ejemplo n.º 14
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)
Ejemplo n.º 15
0
 def execute(self, line, msg_collection: MsgCollection):
     msgstr_1 = line.split('msgstr[2]')[1].strip().strip('"')
     if msg_collection.current_msg:
         current_id = msg_collection.current_msg.id
         msg = msg_collection.get_msg(current_id)
         msg.add_str(msgstr_1)
         return
     raise ValueError()
Ejemplo n.º 16
0
    def test_(self):
        start = State('start')
        machine = StateMachine(start)
        msgid_finded = Event('msgid_finded')
        waiting_msgstr = State('waiting_msgstr')
        start.add_transition(waiting_msgstr, event=msgid_finded)
        controller = Controller(machine, [], MsgCollection())

        controller.handle('msgid_finded', '')

        self.assertEqual(waiting_msgstr, controller.current_state)
Ejemplo n.º 17
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.º 18
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.º 19
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.º 20
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.º 21
0
    def test_add_path_to_current_msg(self):
        expected = Msg(id='Current', paths=['../modules/user/x.js:112'])
        msg_collection = MsgCollection()
        msg_collection.create_current_msg()
        msg_collection.add_path_to_current_msg(path='../modules/user/x.js:112')

        result = msg_collection.current_msg

        self.assertEqual(expected, result)
Ejemplo n.º 22
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.º 23
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.º 24
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
    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)
Ejemplo n.º 26
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()
Ejemplo n.º 27
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.º 28
0
 def __new_controller(cls):
     return Controller(StateMachine(waiting_new_line), command_channel,
                       MsgCollection())
Ejemplo n.º 29
0
 def __init__(self):
     self.ru_msg_collection = MsgCollection()
     self.en_msg_collection = MsgCollection()
     self.new_ru_msg_collection = MsgCollection()
     self.new_en_msg_collection = MsgCollection()