Repository: jerryscript-project/jerryscript
File: tools/runners/test262-harness.py (Python)

Code before:
    @staticmethod
    def instantiate_template(template, params):
        def get_parameter(match):
            key = match.group(1)
            return params.get(key, match.group(0))

        return re.sub(r"\{\{(\w+)\}\}", get_parameter, template)

    @staticmethod
    def execute(command):
        if is_windows():
            args = '%s' % command
        else:
            args = command.split(" ")
        stdout = TempFile(prefix="test262-out-")
        stderr = TempFile(prefix="test262-err-")
        try:
            logging.info("exec: %s", str(args))
            process = subprocess.Popen(
                args,
                shell=False,
                stdout=stdout.file_desc,
                stderr=stderr.file_desc
            )
            timeout = TEST262_CASE_TIMEOUT
            timer = threading.Timer(timeout, process.kill)
            timer.start()
            code = process.wait()
            timer.cancel()
            out = stdout.read()
            err = stderr.read()
        finally:
            stdout.dispose()
            stderr.dispose()
        return (code, out, err)

    def run_test_in(self, tmp):
        tmp.write(self.get_source())
        tmp.close()
        command = TestCase.instantiate_template(self.command_template, {
            'path': tmp.name
        })
        (code, out, err) = TestCase.execute(command)
        return TestResult(code, out, err, self)

    def run(self):
        tmp = TempFile(suffix=".js", prefix="test262-", text=True)
        try:
            result = self.run_test_in(tmp)
        finally:
            tmp.dispose()

Review comment (suggestion):
these two lines can go in a single one (no need for the `timeout` variable when `TEST262_CASE_TIMEOUT` is already there)

Code after:
    @staticmethod
    def instantiate_template(template, params):
        def get_parameter(match):
            key = match.group(1)
            return params.get(key, match.group(0))

        return re.sub(r"\{\{(\w+)\}\}", get_parameter, template)

    @staticmethod
    def execute(command):
        if is_windows():
            args = '%s' % command
        else:
            args = command.split(" ")
        stdout = TempFile(prefix="test262-out-")
        stderr = TempFile(prefix="test262-err-")
        try:
            logging.info("exec: %s", str(args))
            process = subprocess.Popen(
                args,
                shell=False,
                stdout=stdout.file_desc,
                stderr=stderr.file_desc
            )
            timer = threading.Timer(TEST262_CASE_TIMEOUT, process.kill)
            timer.start()
            code = process.wait()
            timer.cancel()
            out = stdout.read()
            err = stderr.read()
        finally:
            stdout.dispose()
            stderr.dispose()
        return (code, out, err)

    def run_test_in(self, tmp):
        tmp.write(self.get_source())
        tmp.close()
        command = TestCase.instantiate_template(self.command_template, {
            'path': tmp.name
        })
        (code, out, err) = TestCase.execute(command)
        return TestResult(code, out, err, self)

    def run(self):
        tmp = TempFile(suffix=".js", prefix="test262-", text=True)
        try:
            result = self.run_test_in(tmp)
        finally:
            tmp.dispose()
        return result