def test_create_current_msg(self): msg_collection = MsgCollection() msg_collection.create_current_msg() result = msg_collection.current_msg self.assertIsNotNone(result)
def test_has_msg(self): msg_collection = MsgCollection() msg_collection.add_msg(id='Box') result = msg_collection.has_msg('Box') self.assertTrue(result)
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)
def test_count(self): expected = 1 msg_collection = MsgCollection() msg_collection.add_msg(id='Box', str='Ящик') result = msg_collection.count self.assertEqual(expected, result)
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)
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)
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)
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)
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)
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)
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)
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)
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_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 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()
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)
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)
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)
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)
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)
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)
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)
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)
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)
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()
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)
def __new_controller(cls): return Controller(StateMachine(waiting_new_line), command_channel, MsgCollection())
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()