示例#1
0
    def test_remove_grammar(self):
        c = Cards.LanguageBVocab(text="machen")
        g = Cards.Grammar(paradigm="this is a grammar")
        g2 = Cards.Grammar(paradigm="this is also a grammar")
        g3 = Cards.Grammar(paradigm="this grammar is not in c")

        self.sess.add_all([c, g, g2, g3])

        c.grammar += [g, g2]
        self.sess.commit()

        self.assertEqual(cds.get_paradigms(c), [g, g2])

        cds.remove_grammar(c, g)
        self.sess.commit()

        c = self.sess.query(Cards.LanguageBVocab).filter_by(id=1).one()
        probe = cds.get_paradigms(c)
        ans = [g2]

        self.assertEqual(probe, ans)

        try:
            cds.remove_grammar(c, g3)
            self.fail()
        except AssertionError:
            print("Caught assertion error")
示例#2
0
    def test_get_paradigms(self):
        c = Cards.LanguageBVocab(text="laufen", g_type="verb")
        g1 = Cards.Grammar(paradigm="laufe, laeufst, laeuft", irregular=True)
        g2 = Cards.Grammar(paradigm="laufe, laufst, lauft", irregular=True)

        self.sess.add_all([c, g1, g2])
        self.sess.commit()

        c.grammar.append(g1)
        c.grammar.append(g2)

        self.sess.commit()

        probe = cds.get_paradigms(c)
        ans = [g1, g2]
        self.assertEqual(probe, ans)
示例#3
0
    def test_add_grammar(self):
        c = Cards.LanguageBVocab(text="machen")
        g = Cards.Grammar(paradigm="machen, mache, machst, macht...")

        self.sess.add_all([c, g])

        cds.add_grammar(c, g)

        probe = cds.get_paradigms(c)
        ans = [g]
        self.assertEqual(probe, ans)
示例#4
0
    def test_grammar(self):
        worda = Cards.LanguageBVocab(text="Ergebnis",
                                     date_created=datetime.date.today(),
                                     g_type="Noun, m")
        wordb = Cards.LanguageBVocab(text="drucken",
                                     date_created=datetime.date.today())
        wordc = Cards.LanguageBVocab(text="weil")

        grammar_b = Cards.Grammar(
            irregular=False, paradigm="drucken, drucke, druckst, druckt, etc")
        grammar_c = Cards.Grammar(paradigm="der Ergebnis, die Ergebnisse")

        self.sess.add(worda)
        self.sess.add(wordb)
        self.sess.add(wordc)

        self.sess.add(grammar_b)
        self.sess.add(grammar_c)

        worda.grammar.append(grammar_c)
        wordb.grammar.append(grammar_b)

        self.sess.commit()

        wa = self.sess.query(Cards.LanguageBVocab).filter_by(id=1).one()
        self.assertEqual(wa.g_type, "Noun, m")

        self.sess.delete(grammar_c)
        self.sess.commit()

        wa = self.sess.query(Cards.LanguageBVocab).filter_by(id=1).one()
        self.assertEqual(len(wa.grammar), 0)

        print(type(worda.text))
        print(str(worda.text))
        print(type(str(worda.text)))
        print(
            datetime.date(worda.date_created.year, worda.date_created.month,
                          worda.date_created.day))
示例#5
0
    def test_edit_paradigm(self):
        import LanguageDeck.session_tools.session_scope as scp
        with scp.session_scope(self.session) as sess:
            c1 = Cards.LanguageAVocab(text="error")
            c2 = Cards.Grammar(paradigm="old paradigm")

            sess.add_all([c1, c2])
            sess.commit()

            try:
                cds.edit_g_paradigm(c1, "new paradigm")
            except AssertionError:
                print("caught assertion error")

            cds.edit_g_paradigm(c2, "new paradigm")
            sess.commit()

            probe = cds.get_paradigm_content(c2)
            ans = "new paradigm"
            self.assertEqual(probe, ans)