Exemple #1
0
    def test_dir(self, root: py.path.local) -> None:
        """Directory and parts."""
        assert resolve_collection_argument(root,
                                           "src/pkg") == (root / "src/pkg", [])

        with pytest.raises(
                UsageError,
                match=r"directory argument cannot contain :: selection parts"):
            resolve_collection_argument(root, "src/pkg::")

        with pytest.raises(
                UsageError,
                match=r"directory argument cannot contain :: selection parts"):
            resolve_collection_argument(root, "src/pkg::foo::bar")
Exemple #2
0
    def test_does_not_exist(self, root):
        """Given a file/module that does not exist raises UsageError."""
        with pytest.raises(
            UsageError, match=re.escape("file or directory not found: foobar")
        ):
            resolve_collection_argument(root, "foobar")

        with pytest.raises(
            UsageError,
            match=re.escape(
                "module or package not found: foobar (missing __init__.py?)"
            ),
        ):
            resolve_collection_argument(root, "foobar", as_pypath=True)
Exemple #3
0
    def test_absolute_paths_are_resolved_correctly(self, invocation_path: Path) -> None:
        """Absolute paths resolve back to absolute paths."""
        full_path = str(invocation_path / "src")
        assert resolve_collection_argument(invocation_path, full_path) == (
            Path(os.path.abspath("src")),
            [],
        )

        # ensure full paths given in the command-line without the drive letter resolve
        # to the full path correctly (#7628)
        drive, full_path_without_drive = os.path.splitdrive(full_path)
        assert resolve_collection_argument(
            invocation_path, full_path_without_drive
        ) == (Path(os.path.abspath("src")), [])
Exemple #4
0
 def test_dir(self, root):
     """Directory and parts."""
     assert resolve_collection_argument(root, "src/pkg") == (root / "src/pkg", [])
     assert resolve_collection_argument(root, "src/pkg::") == (
         root / "src/pkg",
         [""],
     )
     assert resolve_collection_argument(root, "src/pkg::foo::bar") == (
         root / "src/pkg",
         ["foo", "bar"],
     )
     assert resolve_collection_argument(root, "src/pkg::foo::bar::") == (
         root / "src/pkg",
         ["foo", "bar", ""],
     )
Exemple #5
0
    def test_dir(self, invocation_path: Path) -> None:
        """Directory and parts."""
        assert resolve_collection_argument(invocation_path, "src/pkg") == (
            invocation_path / "src/pkg",
            [],
        )

        with pytest.raises(
                UsageError,
                match=r"directory argument cannot contain :: selection parts"):
            resolve_collection_argument(invocation_path, "src/pkg::")

        with pytest.raises(
                UsageError,
                match=r"directory argument cannot contain :: selection parts"):
            resolve_collection_argument(invocation_path, "src/pkg::foo::bar")
Exemple #6
0
 def test_file(self, invocation_dir: py.path.local, invocation_path: Path) -> None:
     """File and parts."""
     assert resolve_collection_argument(invocation_path, "src/pkg/test.py") == (
         invocation_dir / "src/pkg/test.py",
         [],
     )
     assert resolve_collection_argument(invocation_path, "src/pkg/test.py::") == (
         invocation_dir / "src/pkg/test.py",
         [""],
     )
     assert resolve_collection_argument(
         invocation_path, "src/pkg/test.py::foo::bar"
     ) == (invocation_dir / "src/pkg/test.py", ["foo", "bar"])
     assert resolve_collection_argument(
         invocation_path, "src/pkg/test.py::foo::bar::"
     ) == (invocation_dir / "src/pkg/test.py", ["foo", "bar", ""])
Exemple #7
0
 def test_pypath(self, root):
     """Dotted name and parts."""
     assert resolve_collection_argument(root, "pkg.test", as_pypath=True) == (
         root / "src/pkg/test.py",
         [],
     )
     assert resolve_collection_argument(
         root, "pkg.test::foo::bar", as_pypath=True
     ) == (root / "src/pkg/test.py", ["foo", "bar"],)
     assert resolve_collection_argument(root, "pkg", as_pypath=True) == (
         root / "src/pkg",
         [],
     )
     assert resolve_collection_argument(root, "pkg::foo::bar", as_pypath=True) == (
         root / "src/pkg",
         ["foo", "bar"],
     )
Exemple #8
0
 def test_file(self, root):
     """File and parts."""
     assert resolve_collection_argument(root, "src/pkg/test.py") == (
         root / "src/pkg/test.py",
         [],
     )
     assert resolve_collection_argument(root, "src/pkg/test.py::") == (
         root / "src/pkg/test.py",
         [""],
     )
     assert resolve_collection_argument(root, "src/pkg/test.py::foo::bar") == (
         root / "src/pkg/test.py",
         ["foo", "bar"],
     )
     assert resolve_collection_argument(root, "src/pkg/test.py::foo::bar::") == (
         root / "src/pkg/test.py",
         ["foo", "bar", ""],
     )
Exemple #9
0
    def test_pypath(self, invocation_dir: py.path.local, invocation_path: Path) -> None:
        """Dotted name and parts."""
        assert resolve_collection_argument(
            invocation_path, "pkg.test", as_pypath=True
        ) == (invocation_dir / "src/pkg/test.py", [])
        assert resolve_collection_argument(
            invocation_path, "pkg.test::foo::bar", as_pypath=True
        ) == (invocation_dir / "src/pkg/test.py", ["foo", "bar"])
        assert resolve_collection_argument(invocation_path, "pkg", as_pypath=True) == (
            invocation_dir / "src/pkg",
            [],
        )

        with pytest.raises(
            UsageError, match=r"package argument cannot contain :: selection parts"
        ):
            resolve_collection_argument(
                invocation_path, "pkg::foo::bar", as_pypath=True
            )
Exemple #10
0
 def test_parametrized_name_with_colons(self,
                                        invocation_path: Path) -> None:
     ret = resolve_collection_argument(invocation_path,
                                       "src/pkg/test.py::test[a::b]")
     assert ret == (invocation_path / "src/pkg/test.py", ["test[a::b]"])