tests: bound generator subprocesses
This commit is contained in:
@@ -9,13 +9,16 @@ from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
MKEMOJI = ROOT / "map" / "mkemoji"
|
||||
TIMEOUT = 10
|
||||
|
||||
|
||||
def generate(source=None):
|
||||
args = [sys.executable, "-B", str(MKEMOJI)]
|
||||
if source is not None:
|
||||
args.append(str(source))
|
||||
return subprocess.run(args, capture_output=True, text=True, check=False)
|
||||
return subprocess.run(
|
||||
args, capture_output=True, text=True, check=False, timeout=TIMEOUT
|
||||
)
|
||||
|
||||
|
||||
def table(output):
|
||||
|
||||
@@ -11,6 +11,7 @@ from pathlib import Path
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
IMPORT = ROOT / "map" / "libhangul2hanja"
|
||||
GENERATE = ROOT / "map" / "mkhanja"
|
||||
TIMEOUT = 10
|
||||
|
||||
|
||||
def run(program, source=None, stdin=None, hostile=False):
|
||||
@@ -29,6 +30,7 @@ def run(program, source=None, stdin=None, hostile=False):
|
||||
encoding="utf-8",
|
||||
env=env,
|
||||
check=False,
|
||||
timeout=TIMEOUT,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ from pathlib import Path
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
CONVERTER = ROOT / "map" / "skk2ktrans"
|
||||
FIXTURES = Path(__file__).parent / "data" / "skk"
|
||||
TIMEOUT = 10
|
||||
|
||||
|
||||
class Skk2KtransTest(unittest.TestCase):
|
||||
@@ -19,27 +20,31 @@ class Skk2KtransTest(unittest.TestCase):
|
||||
input_path = Path(directory) / "source.skk"
|
||||
input_path.write_bytes(source.encode("euc_jp"))
|
||||
result = subprocess.run(
|
||||
[CONVERTER, input_path], capture_output=True, check=False)
|
||||
[CONVERTER, input_path], capture_output=True, check=False,
|
||||
timeout=TIMEOUT)
|
||||
self.assertEqual(result.returncode, 0, result.stderr.decode())
|
||||
self.assertEqual(result.stdout, expected)
|
||||
|
||||
def test_invalid_euc_jp_is_rejected(self):
|
||||
result = subprocess.run(
|
||||
[CONVERTER], input=b"\xff\xff\n", capture_output=True, check=False)
|
||||
[CONVERTER], input=b"\xff\xff\n", capture_output=True, check=False,
|
||||
timeout=TIMEOUT)
|
||||
self.assertNotEqual(result.returncode, 0)
|
||||
self.assertTrue(result.stderr)
|
||||
|
||||
def test_escaped_candidate_is_rejected(self):
|
||||
source = b"key /escaped\\/slash/\n"
|
||||
result = subprocess.run(
|
||||
[CONVERTER], input=source, capture_output=True, check=False)
|
||||
[CONVERTER], input=source, capture_output=True, check=False,
|
||||
timeout=TIMEOUT)
|
||||
self.assertNotEqual(result.returncode, 0)
|
||||
self.assertIn(b"escaped candidates are unsupported", result.stderr)
|
||||
|
||||
def test_expression_candidate_is_rejected(self):
|
||||
source = b'key /(concat "a/b")/literal/\n'
|
||||
result = subprocess.run(
|
||||
[CONVERTER], input=source, capture_output=True, check=False)
|
||||
[CONVERTER], input=source, capture_output=True, check=False,
|
||||
timeout=TIMEOUT)
|
||||
self.assertNotEqual(result.returncode, 0)
|
||||
self.assertIn(b"expression candidates are unsupported", result.stderr)
|
||||
|
||||
@@ -50,7 +55,8 @@ class Skk2KtransTest(unittest.TestCase):
|
||||
first.write_bytes(b"a /A/")
|
||||
second.write_bytes(b"b /B/\n")
|
||||
result = subprocess.run(
|
||||
[CONVERTER, first, second], capture_output=True, check=False)
|
||||
[CONVERTER, first, second], capture_output=True, check=False,
|
||||
timeout=TIMEOUT)
|
||||
self.assertEqual(result.returncode, 0, result.stderr.decode())
|
||||
self.assertEqual(result.stdout, b"a\tA\nb\tB\n")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user