示例#1
0
 def test_parse_tmx_with_error_no_skip(self):
   tmx_input = StringIO.StringIO(_TMX_WITH_ERRORS)
   tmx_parser = parser_util.TmxParser('en', 'zh', tmx_input)
   with self.assertRaisesRegexp(
       parser_util.InvalidFileFormatError,
       r'No sentence found in source and target languages'):
     list(tmx_parser)
示例#2
0
  def test_invalid_tmx(self):
    tmx_input_stream = StringIO.StringIO("""<tmx><tu></tu></tmx>""")
    tmx_parser = parser_util.TmxParser('en', 'zh', tmx_input_stream)

    with self.assertRaisesRegexp(
        parser_util.InvalidFileFormatError,
        r'Invalid TMX file at line 1: Invalid tag structure'):
      list(tmx_parser)
示例#3
0
  def test_parse_and_export_valid_tmx_tsv(self):
    tmx_input_stream1 = StringIO.StringIO(_VALID_TMX)
    tsv_output_stream1 = StringIO.StringIO()
    tmx_parser1 = parser_util.TmxParser('en', 'zh', tmx_input_stream1)
    tsv_exporter1 = parser_util.TsvExporter('en', 'zh', tsv_output_stream1)
    self._convert(tmx_parser1, tsv_exporter1)
    tsv_output1 = tsv_output_stream1.getvalue()

    tsv_input_stream2 = StringIO.StringIO(tsv_output1)
    tmx_output_stream2 = StringIO.StringIO()
    tsv_parser2 = parser_util.TsvParser('en', 'zh', tsv_input_stream2)
    tmx_exporter2 = parser_util.TmxExporter('en', 'zh', tmx_output_stream2)
    self._convert(tsv_parser2, tmx_exporter2)

    tmx_output_stream2.seek(0)
    tsv_output_stream3 = StringIO.StringIO()
    tmx_parser3 = parser_util.TmxParser('en', 'zh', tmx_output_stream2)
    tsv_exporter3 = parser_util.TsvExporter('en', 'zh', tsv_output_stream3)
    self._convert(tmx_parser3, tsv_exporter3)
    tsv_output3 = tsv_output_stream3.getvalue()
    self.assertEqual(tsv_output1, tsv_output3)
示例#4
0
  def test_parse_empty_tsv(self):
    tsv_input_stream1 = StringIO.StringIO('')
    tmx_output_stream1 = StringIO.StringIO()
    tsv_parser1 = parser_util.TsvParser('en', 'zh', tsv_input_stream1)
    tmx_exporter1 = parser_util.TmxExporter('en', 'zh', tmx_output_stream1)
    self._convert(tsv_parser1, tmx_exporter1)

    tmx_output_stream1.seek(0)
    tsv_output_stream2 = StringIO.StringIO()
    tmx_parser2 = parser_util.TmxParser('en', 'zh', tmx_output_stream1)
    tsv_exporter2 = parser_util.TsvExporter('en', 'zh', tsv_output_stream2)
    self._convert(tmx_parser2, tsv_exporter2)
    self.assertEqual(tsv_output_stream2.getvalue(), '')
示例#5
0
 def test_parse_valid_tmx(self):
   tmx_input_stream1 = StringIO.StringIO(_VALID_TMX)
   tmx_parser1 = parser_util.TmxParser('en', 'zh', tmx_input_stream1)
   pair, = list(tmx_parser1)
   self.assertEqual(pair, ('Hello World', u'你好 世界'))