Ejemplo n.º 1
0
    def test_tmppath_relative_basetemp_absolute(self, tmp_path, monkeypatch):
        from _pytest.tmpdir import TempPathFactory

        monkeypatch.chdir(tmp_path)
        config = FakeConfig("hello")
        t = TempPathFactory.from_config(config)
        assert t.getbasetemp().resolve() == (tmp_path / "hello").resolve()
Ejemplo n.º 2
0
    def test_tmppath_relative_basetemp_absolute(self, tmp_path, monkeypatch):
        from _pytest.tmpdir import TempPathFactory

        monkeypatch.chdir(tmp_path)
        config = FakeConfig("hello")
        t = TempPathFactory.from_config(config)
        assert t.getbasetemp().resolve() == (tmp_path / "hello").resolve()
Ejemplo n.º 3
0
 def test_mktemp(self, tmp_path):
     config = cast(Config, FakeConfig(tmp_path))
     t = TempPathFactory.from_config(config, _ispytest=True)
     tmp = t.mktemp("world")
     assert str(tmp.relative_to(t.getbasetemp())) == "world0"
     tmp = t.mktemp("this")
     assert str(tmp.relative_to(t.getbasetemp())).startswith("this")
     tmp2 = t.mktemp("this")
     assert str(tmp2.relative_to(t.getbasetemp())).startswith("this")
     assert tmp2 != tmp
Ejemplo n.º 4
0
 def test_mktemp(self, tmp_path):
     config = FakeConfig(tmp_path)
     t = TempdirFactory(TempPathFactory.from_config(config))
     tmp = t.mktemp("world")
     assert tmp.relto(t.getbasetemp()) == "world0"
     tmp = t.mktemp("this")
     assert tmp.relto(t.getbasetemp()).startswith("this")
     tmp2 = t.mktemp("this")
     assert tmp2.relto(t.getbasetemp()).startswith("this")
     assert tmp2 != tmp
Ejemplo n.º 5
0
    def test_mktemp(self, testdir):
        from _pytest.tmpdir import TempdirFactory, TempPathFactory

        config = testdir.parseconfig()
        config.option.basetemp = testdir.mkdir("hello")
        t = TempdirFactory(TempPathFactory.from_config(config))
        tmp = t.mktemp("world")
        assert tmp.relto(t.getbasetemp()) == "world0"
        tmp = t.mktemp("this")
        assert tmp.relto(t.getbasetemp()).startswith("this")
        tmp2 = t.mktemp("this")
        assert tmp2.relto(t.getbasetemp()).startswith("this")
        assert tmp2 != tmp
Ejemplo n.º 6
0
    def test_mktemp(self, tmp_path):

        from _pytest.tmpdir import TempdirFactory, TempPathFactory

        config = FakeConfig(tmp_path)
        t = TempdirFactory(TempPathFactory.from_config(config))
        tmp = t.mktemp("world")
        assert tmp.relto(t.getbasetemp()) == "world0"
        tmp = t.mktemp("this")
        assert tmp.relto(t.getbasetemp()).startswith("this")
        tmp2 = t.mktemp("this")
        assert tmp2.relto(t.getbasetemp()).startswith("this")
        assert tmp2 != tmp
Ejemplo n.º 7
0
 def test_tmppath_relative_basetemp_absolute(self, tmp_path, monkeypatch):
     """#4425"""
     monkeypatch.chdir(tmp_path)
     config = cast(Config, FakeConfig("hello"))
     t = TempPathFactory.from_config(config, _ispytest=True)
     assert t.getbasetemp().resolve() == (tmp_path / "hello").resolve()
Ejemplo n.º 8
0
    def runtest(self):
        """Run an AnyScript test item."""

        tmpdir = Path(
            TempdirFactory(TempPathFactory.from_config(self.config)).mktemp(
                self.name))

        with change_dir(tmpdir):
            self.app = AnyPyProcess(**self.app_opts)
            result = self.app.start_macro(self.macro)[0]

        # Ignore error due to missing Main.RunTest
        if "ERROR" in result:
            runtest_missing = any("Error : Main.RunTest :" in err
                                  for err in result["ERROR"])
            if runtest_missing:
                runtest_errros = (
                    "Error : Main.RunTest : Unresolved",
                    "Main.RunTest : Select Operation",
                    "Error : run : command unexpected while",
                )
                result["ERROR"][:] = [
                    err for err in result["ERROR"]
                    if not any(s in err for s in runtest_errros)
                ]
        # Check that the expected errors are present
        error_list = result.get("ERROR", [])
        if self.expect_errors:
            for xerr in self.expect_errors:
                xerr_found = False
                for error in error_list[:]:
                    if xerr in error:
                        xerr_found = True
                        error_list.remove(error)
                if not xerr_found:
                    self.errors.append("TEST ERROR: Expected error not "
                                       'found: "{}"'.format(xerr))

        # Add remaining errors to item's error list
        if error_list:
            self.errors.extend(error_list)

        # Add info to the hdf5 file if compare output was set
        if self.hdf5_outputs:
            base = Path(self.config.getoption("--anytest-output"))
            subfolder = Path(self.config.getoption("--anytest-name"))
            target = base / subfolder / self.name
            self.save_output_files(tmpdir, target, result, self.hdf5_outputs)

        if self.errors and self.config.getoption("--create-macros"):
            logfile = result["task_logfile"]
            shutil.copyfile(logfile, self.fspath / (self.name + ".txt"))
            shutil.copyfile(logfile.with_suffix(".anymcr"),
                            self.fspath / (self.name + ".anymcr"))
            macro_name = _write_macro_file(self.fspath.dirname, self.name,
                                           self.macro)

        shutil.rmtree(tmpdir, ignore_errors=True)

        if len(self.errors) > 0:
            raise AnyException(self)

        return