Ejemplo n.º 1
0
    def testJoin(self):
        """ The join function takes lists of items and joins them """

        v = join(", ")[Person.lastFirst(all("author"))]
        self._cmp(v, u"Gobry, Frédéric, Fobry, Grédéric, Dobry, Lrédéric")

        v = join(", ")["a", "b", "c"]
        self._cmp(v, u"a, b, c")

        v = join(", ", last="; ")["a", "b", "c"]
        self._cmp(v, u"a, b; c")

        v = join(", ")["a", "b", "c"] + " ok"
        self._cmp(v, u"a, b, c ok")

        # join skip missing values
        v = join(", ")[one("title"), one("journal"), one("gronf")]
        self._cmp(v, u"My title")

        # join fails when _no_ value is available
        v = join(", ")[one("gronf"), one("regronf")]
        phase2 = v(self.db)
        try:
            phase2(self.rec)
            assert False
        except DSL.Missing:
            pass

        # Join with a weird tag in the middle.
        v = "a " + join(BR)["toto", "tutu"] + " b"

        self._cmp(v, u"a toto<br>tutu b")
        return