#!/usr/bin/python3 # -*- coding: utf-8 -*- from base_test import IOTest import unittest from subprocess import call class TransferTest(IOTest, unittest.TestCase): """Subclass and override inputs/expectedOutputs (and possibly other stuff) to create new postchunk tests.""" bindata = "data/nno-nob.t1x.bin" t1xdata = "data/apertium-nno-nob.nob-nno.t1x" flags = ["-b", "-z"] inputs = [""] expectedOutputs = [""] expectedCompRetCodeFail = False def compile(self): retCode = call(["../apertium/apertium-preprocess-transfer", self.t1xdata, self.bindata]) if self.expectedCompRetCodeFail: self.assertNotEqual(retCode, 0) else: self.assertEqual(retCode, 0) return retCode == 0 def runTest(self): if not self.compile(): return cmd = ["../apertium/apertium-transfer"] \ + self.flags \ + [self.t1xdata, self.bindata] self.runCommand(cmd, zip(self.inputs, self.expectedOutputs)) class BasicTransferTest(TransferTest): inputs = ["^hun/ho$"] expectedOutputs = ["^prn{^ho$}$"] class SlashTagTest(TransferTest): inputs = ['^hun/ho$'] expectedOutputs = ['^prn{^ho$}$'] class SlLemqTest(TransferTest): inputs = ["^skyldes/komme# av$"] expectedOutputs = ["sl-lemq:'' tl-lemq:'# av'"] class WordboundBlankTest(TransferTest): inputs = ["[blank1] [[t:s:123456]]^worda/wordta$ ;[blank2]; [[t:b:xyz123; t:l:xyz347]]^wordb/wordtb$ [blank3]; [[t:i:abc123; t:s:abc123]]^hun/ho$"] expectedOutputs = ["[blank1] ^prn{[[t:i:abc123; t:s:abc123]]^ho$[[t:b:xyz123; t:l:xyz347]]^wordtb$}$ ;[blank2]; ^det{[[t:s:123456; t:i:abc123; t:s:abc123]]^wordta+ho$}$ [blank3]; "] class SingleLUWordboundBlankTest(TransferTest): inputs = ["[blank1] [[t:s:123456]]^worda/wordta$ ;[blank2]; [[t:b:xyz123; t:l:xyz347]]^wordb/wordtb$ [blank3]; "] expectedOutputs = ["[blank1] ^nacr{[[t:s:123456]]^test$ [[t:s:123456]]^wordta$}$ ^nacr2{[[t:s:123456]]^testlem$ [[t:s:123456]]^wordta+postp$}$ ;[blank2]; ^nacr{[[t:b:xyz123; t:l:xyz347]]^test$ [[t:b:xyz123; t:l:xyz347]]^wordtb$}$ ^nacr2{[[t:b:xyz123; t:l:xyz347]]^testlem$ [[t:b:xyz123; t:l:xyz347]]^wordtb+postp$}$ [blank3]; "] class SuperblankTest(TransferTest): inputs = [ "[blank1] ^worda/wordta$ ;[blank2]; ^wordb/wordtb$ [blank3]; ^hun/ho$ [blank4] ", #Rule: superblankrule1 -> No in rule output, should flush all blanks after rule output "[blank1] ^worda/wordta$ ;[blank2]; ^wordb/wordtb$ [blank3]; ^hun/ho$ [blank4] ", #No rule matches, should print all blanks as is "[blank1] ^wordb/wordtb$ ;[blank2]; ^worda/wordta$ [blank3]; ^hun/ho$ [blank4] ", #Rule: superblankrule2 -> One in rule output, should print one and flush the rest "[blank1] ^hun/ho$ ;[blank2]; ^worda/wordta$ [blank3]; [blank4] ", #Rule: superblankrule3 -> Input rule has 1 blank, output has 3, should print input blank for the first and just spaces for the rest "[blank1] ^hun/ho$ ;[blank2]; ^worda/wordta$ [blank3]; ^wordb/wordtb$ ;[blank4]; ^worda/wordta$ [blank5]; ^hun/ho$ [blank6] "] #Multiple rule matches expectedOutputs = [ "[blank1] ^test1{^wordta$^wordtb$^ho$}$ ;[blank2]; [blank3]; [blank4] ", "[blank1] ^default{^wordta$}$ ;[blank2]; ^default{^wordtb$}$ [blank3]; ^default{^ho$}$ [blank4] ", "[blank1] ^test1{^wordta$ ;[blank2]; ^ho$}$ [blank3]; [blank4] ", "[blank1] ^test1{^ho$ ;[blank2]; ^wordta$ ^ho$ ^wordta$}$ [blank3]; [blank4] ", "[blank1] ^test1{^ho$ ;[blank2]; ^wordta$ ^ho$ ^wordta$}$ [blank3]; ^test1{^wordta$ ;[blank4]; ^ho$}$ [blank5]; [blank6] "] class BincompatTest(BasicTransferTest): bindata = "data/bincompat.t1x.bin" def compile(self): return True class EmptyTransferTest(TransferTest): t1xdata = "data/empty.t1x" inputs = ["^hun/ho$"] expectedOutputs = ["^default{^ho$}$"] class BadAttrTest(TransferTest): t1xdata = "data/bad-attr.t1x" expectedCompRetCodeFail = True class SlashLuTransferTest(TransferTest): t1xdata = "data/lu.t1x" inputs = ["^hun/ho$", '^a<2/3>/b$'] expectedOutputs = ["^ho<1/2>$", '^b$']