#!/usr/bin/python3 # -*- coding: utf-8 -*- from base_test import IOTest import unittest class InterchunkTest(IOTest, unittest.TestCase): """Subclass and override inputs/expectedOutputs (and possibly other stuff) to create new interchunk tests.""" bindata = "data/nno-nob.t2x.bin" t2xdata = "data/apertium-nno-nob.nno-nob.t2x" flags = ["-z"] inputs = [""] expectedOutputs = [""] def compile(self): self.checkCommand(['../apertium/apertium-preprocess-transfer', self.t2xdata, self.bindata]) def runTest(self): self.compile() cmd = ['../apertium/apertium-interchunk'] \ + self.flags \ + [self.t2xdata, self.bindata] self.runCommand(cmd, zip(self.inputs, self.expectedOutputs)) class SimpleInterchunkTest(InterchunkTest): inputs = ["^prn{^ho$}$ ^prn2{^ho$}$", "^vblex{^gå$}$^default{^.$}$"] expectedOutputs = ["^prn2{^ho$}$^prn{^ho$}$", "^vblex{^gå$}$^default{^.$}$"] class WordboundBlankTest(InterchunkTest): inputs = ["^n_n{[[t:b:123456]]^worda$ ;[testblank] [[t:s:xyzab12]]^wordb# xyz$}$", "^prn{[[t:b:abc823]]^ho$}$ ^prn2{[[t:i:poa023; t:span:12xas23]]^ho$}$"] expectedOutputs = ["^n_n{[[t:b:123456]]^worda$ ;[testblank] [[t:s:xyzab12]]^wordb# xyz$}$", "^prn2{[[t:i:poa023; t:span:12xas23]]^ho$}$^prn{[[t:b:abc823]]^ho$}$"] class SuperblankTest(InterchunkTest): inputs = [ "[blank1];; ^test1{^worda$}$ ;[blank2] ^test2{^wordb# xyz$}$ ;[blank3]; ^test3{^wordc# xyz$}$ [blank4];;", #superblankrule1 "[blank1];; ^test1{^worda$}$ ;[blank2] ^test2{^wordb# xyz$}$ ;[blank3]; ^test3{^wordc# xyz$}$ [blank4];;", #Blanks when no rules match "[blank1];; ^test2{^worda$}$ ;[blank2] ^test2{^wordb# xyz$}$ ;[blank3]; ^test3{^wordc# xyz$}$ [blank4];;", #superblankrule2 -> When output rule has more than input blanks, print all then spaces "[blank1];; ^test3{^worda$}$ ;[blank2] ^test2{^wordb# xyz$}$ ;[blank3]; ^test1{^wordc# xyz$}$ [blank4];;", #superblankrule3 -> Output rule has no , flush all blanks after rule output "[blank1];; ^test1{^worda$}$ ;[blank2] ^test3{^wordb# xyz$}$ ;[blank3]; ^test2{^wordc# xyz$}$ [blank4];;", #superblankrule4 -> Output rule has one , print one blank, then flush all after rule output "[blank1];; ^test1{^worda$}$ ;[blank2] ^test2{^wordb# xyz$}$ ;[blank3]; ^test3{^wordc# xyz$}$ [blank4];; ^test1{^worda$}$ ;[blank5] ^test3{^wordb# xyz$}$ ;[blank6]; ^test2{^wordc# xyz$}$ [blank7];;", #Multiple matching rules -> superblankrule1 & superblankrule4 "[blank1];; ^test1{^worda$}$ ;[blank2] ^test2{^wordb# xyz$}$ ;[blank3]; ^test2x{^wordc# xyz$}$ [blank4];; ^test2{^wordb# xyz$}$ ;[blank5];"] #Rule followed by unknown expectedOutputs = [ "[blank1];; ^test2{^wordb# xyz$}$ ;[blank2] ^test1{^worda$}$ ;[blank3]; ^test3{^wordc# xyz$}$ [blank4];;", "[blank1];; ^test1{^worda$}$ ;[blank2] ^test2{^wordb# xyz$}$ ;[blank3]; ^test3{^wordc# xyz$}$ [blank4];;", "[blank1];; ^test2{^wordb# xyz$}$ ;[blank2] ^test2{^worda$}$ ;[blank3]; ^test2{^wordb# xyz$}$ ^test2{^worda$}$ ^test3{^wordc# xyz$}$ [blank4];;", "[blank1];; ^test2{^wordb# xyz$}$^test3{^worda$}$^test1{^wordc# xyz$}$ ;[blank2] ;[blank3]; [blank4];;", "[blank1];; ^test3{^wordb# xyz$}$^test1{^worda$}$ ;[blank2] ^test2{^wordc# xyz$}$ ;[blank3]; [blank4];;", "[blank1];; ^test2{^wordb# xyz$}$ ;[blank2] ^test1{^worda$}$ ;[blank3]; ^test3{^wordc# xyz$}$ [blank4];; ^test3{^wordb# xyz$}$^test1{^worda$}$ ;[blank5] ^test2{^wordc# xyz$}$ ;[blank6]; [blank7];;", "[blank1];; ^test2{^wordb# xyz$}$ ;[blank2] ^test1{^worda$}$ ;[blank3]; ^test2x{^wordc# xyz$}$ [blank4];; ^test2{^wordb# xyz$}$ ;[blank5];"] class BincompatTest(SimpleInterchunkTest): bindata = "data/bincompat.t2x.bin" def compile(self): pass class EmptyTransferTest(InterchunkTest): t2xdata = "data/empty.t1x" inputs = ["^default{^ho$}$"] expectedOutputs = ["^default{^ho$}$"]