Repository: pytest-dev/pytest
File: testing/_py/test_local.py (Python)

Code before:
        assert path1.join("sampledir") in p
        assert path1.join("samplefile") not in p

    def test_listdir_sorted(self, path1):
        p = path1.listdir(lambda x: x.check(basestarts="sample"), sort=True)
        assert path1.join("sampledir") == p[0]
        assert path1.join("samplefile") == p[1]
        assert path1.join("samplepickle") == p[2]

    def test_visit_nofilter(self, path1):
        lst = []
        for i in path1.visit():
            lst.append(i.relto(path1))
        assert "sampledir" in lst
        assert path1.sep.join(["sampledir", "otherfile"]) in lst

    def test_visit_norecurse(self, path1):
        lst = []
        for i in path1.visit(None, lambda x: x.basename != "sampledir"):
            lst.append(i.relto(path1))
        assert "sampledir" in lst
        assert path1.sep.join(["sampledir", "otherfile"]) not in lst

    @pytest.mark.parametrize(
        "fil",
        ["*dir", "*dir", pytest.mark.skip("sys.version_info < (3,6)")(b"*dir")],
    )
    def test_visit_filterfunc_is_string(self, path1, fil):
        lst = []
        for i in path1.visit(fil):
            lst.append(i.relto(path1))
        assert len(lst), 2
        assert "sampledir" in lst
        assert "otherdir" in lst

    def test_visit_ignore(self, path1):
        p = path1.join("nonexisting")
        assert list(p.visit(ignore=error.ENOENT)) == []

    def test_visit_endswith(self, path1):
        p = []
        for i in path1.visit(lambda x: x.check(endswith="file")):
            p.append(i.relto(path1))
        assert path1.sep.join(["sampledir", "otherfile"]) in p
        assert "samplefile" in p

    def test_cmp(self, path1):
        path1 = path1.join("samplefile")
        path2 = path1.join("samplefile2")
        assert (path1 < path2) == ("samplefile" < "samplefile2")
        assert not (path1 < path1)

Review comment (refactor):
We can remove this:

```suggestion
        ["*dir", "*dir", b"*dir"],
```

Code after:
        assert path1.join("sampledir") in p
        assert path1.join("samplefile") not in p

    def test_listdir_sorted(self, path1):
        p = path1.listdir(lambda x: x.check(basestarts="sample"), sort=True)
        assert path1.join("sampledir") == p[0]
        assert path1.join("samplefile") == p[1]
        assert path1.join("samplepickle") == p[2]

    def test_visit_nofilter(self, path1):
        lst = []
        for i in path1.visit():
            lst.append(i.relto(path1))
        assert "sampledir" in lst
        assert path1.sep.join(["sampledir", "otherfile"]) in lst

    def test_visit_norecurse(self, path1):
        lst = []
        for i in path1.visit(None, lambda x: x.basename != "sampledir"):
            lst.append(i.relto(path1))
        assert "sampledir" in lst
        assert path1.sep.join(["sampledir", "otherfile"]) not in lst

    @pytest.mark.parametrize(
        "fil",
        ["*dir", "*dir", pytest.mark.skip("sys.version_info <" " (3,6)")(b"*dir")],
    )
    def test_visit_filterfunc_is_string(self, path1, fil):
        lst = []
        for i in path1.visit(fil):
            lst.append(i.relto(path1))
        assert len(lst), 2
        assert "sampledir" in lst
        assert "otherdir" in lst

    def test_visit_ignore(self, path1):
        p = path1.join("nonexisting")
        assert list(p.visit(ignore=error.ENOENT)) == []

    def test_visit_endswith(self, path1):
        p = []
        for i in path1.visit(lambda x: x.check(endswith="file")):
            p.append(i.relto(path1))
        assert path1.sep.join(["sampledir", "otherfile"]) in p
        assert "samplefile" in p

    def test_cmp(self, path1):
        path1 = path1.join("samplefile")
        path2 = path1.join("samplefile2")
        assert (path1 < path2) == ("samplefile" < "samplefile2")
        assert not (path1 < path1)