File: __init__.py

package info (click to toggle)
apertium 3.9.12-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,024 kB
  • sloc: cpp: 22,288; ansic: 4,875; xml: 2,566; python: 1,428; sh: 1,117; lex: 1,088; makefile: 591
file content (46 lines) | stat: -rw-r--r-- 1,939 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import unittest

from subprocess import run


class CleanstreamTest(unittest.TestCase):
    """Subclass and override inputs/expectedOutputs (and possibly other
stuff) to create new cleanstream tests."""

    flags = [""]
    inputs = [""]
    expectedOutputs = [""]
    expectedRetCodeFail = False

    def runTest(self):
        for inp, exp in zip(self.inputs, self.expectedOutputs):
            with self.subTest(input_line=inp):
                proc = run(
                    ["../apertium/apertium-cleanstream"] + self.flags,
                    input=inp.encode('utf-8'), capture_output=True, check=False,
                )
                self.assertEqual(proc.stderr.decode('utf-8'), "")
                self.assertEqual(proc.stdout.decode('utf-8'), exp)
                if self.expectedRetCodeFail:
                    self.assertNotEqual(0, proc.returncode)
                else:
                    self.assertEqual(0, proc.returncode)

class BasicCleanstream(CleanstreamTest):
    inputs =          ["^a<n>$ ^a<n>$", "^a<n>+c<po>$", "^a<vblex><pres># b$", "[<div>]^x<n>$", "[<div>]\\^^a<vblex><pres># b$"]
    expectedOutputs = ["^a<n>$ ^a<n>$", "^a<n>+c<po>$", "^a<vblex><pres># b$", " ^x<n>$",        "  ^a<vblex><pres># b$"]


class NewlineCleanstream(CleanstreamTest):
    flags = ["-n"]
    inputs =          ["^a<n>$ ^a<n>$", "^a<n>+c<po>$", "^a<vblex><pres># b$", "[<div>]^x<n>$", "[<div>]\\^^a<vblex><pres># b$"]
    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"]


class KeepblankCleanstream(CleanstreamTest):
    flags = ["-b"]
    inputs =          ["^a<n>$ ^a<n>$", "^a<n>+c<po>$", "^a<vblex><pres># b$", "[<div>]^x<n>$", "[<div>]\\^^a<vblex><pres># b$"]
    expectedOutputs = ["^a<n>$ ^a<n>$", "^a<n>+c<po>$", "^a<vblex><pres># b$", " [<div>]^x<n>$", " [<div>] ^a<vblex><pres># b$"]