| 1 |
#!/usr/bin/python3 |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
|
| 4 |
import unittest |
| 5 |
|
| 6 |
from subprocess import run |
| 7 |
|
| 8 |
|
| 9 |
class CleanstreamTest(unittest.TestCase): |
| 10 |
"""Subclass and override inputs/expectedOutputs (and possibly other |
| 11 |
stuff) to create new cleanstream tests.""" |
| 12 |
|
| 13 |
flags = [""] |
| 14 |
inputs = [""] |
| 15 |
expectedOutputs = [""] |
| 16 |
expectedRetCodeFail = False |
| 17 |
|
| 18 |
def runTest(self): |
| 19 |
for inp, exp in zip(self.inputs, self.expectedOutputs): |
| 20 |
with self.subTest(input_line=inp): |
| 21 |
proc = run( |
| 22 |
["../apertium/apertium-cleanstream"] + self.flags, |
| 23 |
input=inp.encode('utf-8'), capture_output=True, check=False, |
| 24 |
) |
| 25 |
self.assertEqual(proc.stderr.decode('utf-8'), "") |
| 26 |
self.assertEqual(proc.stdout.decode('utf-8'), exp) |
| 27 |
if self.expectedRetCodeFail: |
| 28 |
self.assertNotEqual(0, proc.returncode) |
| 29 |
else: |
| 30 |
self.assertEqual(0, proc.returncode) |
| 31 |
|
| 32 |
class BasicCleanstream(CleanstreamTest): |
| 33 |
inputs = ["^a<n>$ ^a<n>$", "^a<n>+c<po>$", "^a<vblex><pres># b$", "[<div>]^x<n>$", "[<div>]\\^^a<vblex><pres># b$"] |
| 34 |
expectedOutputs = ["^a<n>$ ^a<n>$", "^a<n>+c<po>$", "^a<vblex><pres># b$", " ^x<n>$", " ^a<vblex><pres># b$"] |
| 35 |
|
| 36 |
|
| 37 |
class NewlineCleanstream(CleanstreamTest): |
| 38 |
flags = ["-n"] |
| 39 |
inputs = ["^a<n>$ ^a<n>$", "^a<n>+c<po>$", "^a<vblex><pres># b$", "[<div>]^x<n>$", "[<div>]\\^^a<vblex><pres># b$"] |
| 40 |
expectedOutputs = ["\n^a<n>$\n^a<n>$\n", "\n^a<n>+c<po>$\n", "\n^a<vblex><pres># b$\n", "\n\n^x<n>$\n", "\n\n^a<vblex><pres># b$\n"] |
| 41 |
|
| 42 |
|
| 43 |
class KeepblankCleanstream(CleanstreamTest): |
| 44 |
flags = ["-b"] |
| 45 |
inputs = ["^a<n>$ ^a<n>$", "^a<n>+c<po>$", "^a<vblex><pres># b$", "[<div>]^x<n>$", "[<div>]\\^^a<vblex><pres># b$"] |
| 46 |
expectedOutputs = ["^a<n>$ ^a<n>$", "^a<n>+c<po>$", "^a<vblex><pres># b$", " [<div>]^x<n>$", " [<div>] ^a<vblex><pres># b$"] |