Ejemplo n.º 1
0
    def test_selector_wrapper(self):

        elements = [
            Element("foo/a.ext"),
            Element("foo/b.tld"),
            Element("bar/c.ext"),
            Element("bar/d.tld"),
        ]

        project = Project(elements, dict(), dict())

        pattern = "foo/*"
        patternSelector = Pattern(pattern)
        patternGuess = Selector(pattern)

        iterable = elements[2:]
        iterableSelector = Elements(iterable)
        iterableGuess = Selector(iterable)

        # Selector called on a pattern string should return a PathPatternSelector
        assert isinstance(patternGuess, Pattern)

        # Selector called on an iterable on Elements should return a ElementsSelector
        assert isinstance(iterableGuess, Elements)

        # Double-check equivalence
        assert set(patternGuess(project)) == set(patternSelector(project))
        assert set(iterableGuess(project)) == set(iterableSelector(project))
Ejemplo n.º 2
0
    def test_init(self):

        text = "Lorem ipsum blahblah"
        path = Path("/test/foo/bar.ext")

        d = Element(path, arg1="Foo")
        d._contents = text

        assert d._filename == "bar.ext"
        assert str(d) == text
        assert getattr(d, "arg1") == "Foo"
        assert d._metadata() == {"arg1": "Foo"}
Ejemplo n.º 3
0
    def test_selector_all(self):

        elements = [
            Element("foo/a.ext"),
            Element("foo/b.tld"),
            Element("bar/c.ext"),
            Element("bar/d.tld"),
        ]

        project = Project(elements, dict(), dict())

        assert set(All()(project)) == set(elements)
Ejemplo n.º 4
0
    def test_selector_elements(self):

        elements = [
            Element("foo/a.ext"),
            Element("foo/b.tld"),
            Element("bar/c.ext"),
            Element("bar/d.tld"),
        ]

        project = Project(elements, dict(), dict())

        selector = Elements(elements[2:])

        assert set(selector(project)) == set(elements[2:])
Ejemplo n.º 5
0
    def test_selector_collection(self):

        elements = [
            Element("foo/a.ext"),
            Element("foo/b.tld"),
            Element("bar/c.ext"),
            Element("bar/d.tld"),
        ]

        project = Project(elements, dict(), dict())
        collection = BaseCollection("test")
        collection.add(elements[0])
        collection.add(elements[1])
        collection(project)

        assert set(Collection("test")(project)) == set(project.elements[:2])
Ejemplo n.º 6
0
    def test_selector_pattern(self):

        elements = [
            Element("foo/a.ext"),
            Element("foo/b.tld"),
            Element("bar/c.ext"),
            Element("bar/d.tld"),
        ]

        project = Project(elements, dict(), dict())

        s1 = Pattern("bar/*")
        s2 = Pattern("*.tld")

        assert set(s1(project)) == {elements[2], elements[3]}
        assert set(s2(project)) == {elements[1], elements[3]}
Ejemplo n.º 7
0
    def test_selector_extension(self):

        elements = [
            Element("foo/a.ext"),
            Element("foo/b.tld"),
            Element("bar/c.ext"),
            Element("bar/d.tld"),
        ]

        project = Project(elements, dict(), dict())

        s1 = Extensions("ext")
        s2 = Extensions("EXT")
        s3 = Extensions(".ext")

        assert (set(s1(project)) == set(s2(project)) == set(s3(project)) ==
                {elements[0], elements[2]})
Ejemplo n.º 8
0
    def test_update(self):

        text = "Lorem ipsum blahblah"
        path = Path("/test/foo/bar.ext")

        d = Element(path, arg1="Foo")
        d._contents = text

        metadata = {"arg2": "Bar"}

        d._update_metadata(metadata)

        assert getattr(d, "arg2") == "Bar"
        assert d._metadata() == {"arg1": "Foo", "arg2": "Bar"}

        # TODO: Check pertinence
        d._contents = "Test"

        assert str(d) == "Test"
        assert getattr(d, "arg2") == "Bar"
        assert d._metadata() == {"arg1": "Foo", "arg2": "Bar"}