syntax_tests.py 812 Bytes
Newer Older
Johannes Bechberger's avatar
Johannes Bechberger committed
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
from mjtest.environment import Environment, TestMode
from mjtest.test.tests import TestCase, TestResult, BasicTestResult
from os import path


class BasicSyntaxTest(TestCase):

    FILE_ENDINGS = [".invalid.mj", ".valid.mj", ".mj"]

    def __init__(self, env: Environment, type: str, file: str):
        super().__init__(env, type, file)
        self._should_succeed = not file.endswith(".invalid.mj")

    def should_succeed(self) -> bool:
        return self._should_succeed

    def short_name(self) -> str:
        return path.basename(self.file)[:-3]

    def run(self) -> TestResult:
        out, err, rtcode = self.env.run_mj_command("--parsetest ", self.file)
        return BasicTestResult(self, rtcode, out.decode(), err.decode())

TestCase.TEST_CASE_CLASSES[TestMode.syntax].append(BasicSyntaxTest)