예제 #1
0
 def test_print_from(self):
     self.assertParse(
         qp.Print(
             qp.From(
                 qp.Equal(qp.Column('date'),
                          qp.Constant(datetime.date(2014, 1, 1))), None,
                 True, None)), "PRINT FROM date = 2014-01-01 CLOSE;")
예제 #2
0
 def test_journal_with_account_func_and_from(self):
     journal = self.parse("JOURNAL 'liabilities' AT cost FROM year = 2014;")
     select = qc.transform_journal(journal)
     self.assertEqual(
         select,
         qp.Select([
             qp.Target(qp.Column('date'), None),
             qp.Target(qp.Column('flag'), None),
             qp.Target(
                 qp.Function('maxwidth',
                             [qp.Column('payee'),
                              qp.Constant(48)]), None),
             qp.Target(
                 qp.Function('maxwidth',
                             [qp.Column('narration'),
                              qp.Constant(80)]), None),
             qp.Target(qp.Column('account'), None),
             qp.Target(qp.Function('cost', [qp.Column('position')]), None),
             qp.Target(qp.Function('cost', [qp.Column('balance')]), None),
         ],
                   qp.From(qp.Equal(qp.Column('year'), qp.Constant(2014)),
                           None, None, None),
                   qp.Match(qp.Column('account'),
                            qp.Constant('liabilities')), None, None, None,
                   None, None))
예제 #3
0
 def test_journal_from(self):
     self.assertParse(
         qp.Journal(
             None, None,
             qp.From(
                 qp.Equal(qp.Column('date'),
                          qp.Constant(datetime.date(2014, 1, 1))), None,
                 True, None)), "JOURNAL FROM date = 2014-01-01 CLOSE;")
예제 #4
0
 def test_both(self):
     self.assertParse(
         qSelect(self.targets, qp.From(self.expr, None, None, None),
                 self.expr), """
       SELECT a, b
       FROM d = (max(e) and 17)
       WHERE d = (max(e) and 17);
     """)
예제 #5
0
 def test_balances_from_with_transformer(self):
     self.assertParse(
         "BALANCES AT units FROM date = 2014-01-01 CLOSE;",
         qp.Balances(
             'units',
             qp.From(
                 qp.Equal(qp.Column('date'),
                          qp.Constant(datetime.date(2014, 1, 1))), None,
                 True, None), None))
예제 #6
0
 def test_from_open_close_clear(self):
     self.assertParse(
         qSelect(
             self.targets,
             qp.From(self.expr, datetime.date(2013, 10, 25),
                     datetime.date(2014, 10, 25), True)), """
       SELECT a, b
       FROM d = (max(e) and 17) OPEN ON 2013-10-25 CLOSE ON 2014-10-25 CLEAR;
     """)
예제 #7
0
 def test_balances_from(self):
     self.assertParse(
         "BALANCES FROM date = 2014-01-01 CLOSE;",
         qp.Balances(
             None,
             qp.From(
                 qp.Equal(qp.Column('date'),
                          qp.Constant(datetime.date(2014, 1, 1))), None,
                 True, None), None))
예제 #8
0
 def test_from_and_where(self):
     expr = qp.Equal(
         qp.Column('d'),
         qp.And(qp.Function('max', [qp.Column('e')]), qp.Constant(17)))
     self.assertParse(
         "SELECT a, b FROM d = (max(e) and 17) WHERE d = (max(e) and 17);",
         Select([
             qp.Target(qp.Column('a'), None),
             qp.Target(qp.Column('b'), None)
         ], qp.From(expr, None, None, None), expr))
예제 #9
0
 def test_balance_with_units_and_from(self):
     balance = self.parse("BALANCES AT cost FROM year = 2014;")
     select = qc.transform_balances(balance)
     self.assertEqual(
         qp.Select([
             qp.Target(qp.Column('account'), None),
             qp.Target(
                 qp.Function(
                     'sum', [qp.Function('cost', [qp.Column('position')])]),
                 None),
         ],
                   qp.From(qp.Equal(qp.Column('year'), qp.Constant(2014)),
                           None, None, None), None, self.group_by,
                   self.order_by, None, None, None, None), select)
예제 #10
0
    def test_select_from(self):
        expr = qp.Equal(
            qp.Column('d'),
            qp.And(qp.Function('max', [qp.Column('e')]), qp.Constant(17)))

        with self.assertRaises(qp.ParseError):
            self.parse("SELECT a, b FROM;")

        # simple
        self.assertParseFrom("SELECT a, b FROM d = (max(e) and 17);",
                             qp.From(expr, None, None, None))

        # open dated
        self.assertParseFrom(
            "SELECT a, b FROM d = (max(e) and 17) OPEN ON 2014-01-01;",
            qp.From(expr, datetime.date(2014, 1, 1), None, None))

        # close default
        self.assertParseFrom("SELECT a, b FROM d = (max(e) and 17) CLOSE;",
                             qp.From(expr, None, True, None))

        # close dated
        self.assertParseFrom(
            "SELECT a, b FROM d = (max(e) and 17) CLOSE ON 2014-10-18;",
            qp.From(expr, None, datetime.date(2014, 10, 18), None))

        # close no expression
        self.assertParseFrom("SELECT a, b FROM CLOSE;",
                             qp.From(None, None, True, None))

        # close no expression dated
        self.assertParseFrom(
            "SELECT a, b FROM CLOSE ON 2014-10-18;",
            qp.From(None, None, datetime.date(2014, 10, 18), None))

        # clear default
        self.assertParseFrom("SELECT a, b FROM d = (max(e) and 17) CLEAR;",
                             qp.From(expr, None, None, True))

        # open close clear
        self.assertParseFrom(
            "SELECT a, b FROM d = (max(e) and 17) OPEN ON 2013-10-25 CLOSE ON 2014-10-25 CLEAR;",
            qp.From(expr, datetime.date(2013, 10, 25),
                    datetime.date(2014, 10, 25), True))
예제 #11
0
 def test_from_select(self):
     self.assertParse(
         """
         SELECT a, b FROM (
           SELECT * FROM date = 2014-05-02
         ) WHERE c = 5 LIMIT 100;""",
         Select([
             qp.Target(qp.Column('a'), None),
             qp.Target(qp.Column('b'), None)
         ],
                Select(
                    qp.Wildcard(),
                    qp.From(
                        qp.Equal(qp.Column('date'),
                                 qp.Constant(datetime.date(2014, 5, 2))),
                        None, None, None)),
                qp.Equal(qp.Column('c'), qp.Constant(5)),
                limit=100))
예제 #12
0
 def test_from(self):
     self.assertParse(
         qSelect(self.targets, qp.From(self.expr, None, None, None)),
         "SELECT a, b FROM d = (max(e) and 17);")
예제 #13
0
 def test_from_open_default(self):
     self.assertParse(
         qSelect(self.targets,
                 qp.From(self.expr, datetime.date(2014, 1, 1), None, None)),
         "SELECT a, b FROM d = (max(e) and 17) OPEN ON 2014-01-01;")
예제 #14
0
 def test_from_close_dated(self):
     self.assertParse(
         qSelect(
             self.targets,
             qp.From(self.expr, None, datetime.date(2014, 10, 18), None)),
         "SELECT a, b FROM d = (max(e) and 17) CLOSE ON 2014-10-18;")
예제 #15
0
 def test_from_clear_default(self):
     self.assertParse(
         qSelect(self.targets, qp.From(self.expr, None, None, True)),
         "SELECT a, b FROM d = (max(e) and 17) CLEAR;")
예제 #16
0
 def test_from_close_no_expr_dated(self):
     self.assertParse(
         qSelect(self.targets,
                 qp.From(None, None, datetime.date(2014, 10, 18), None)),
         "SELECT a, b FROM CLOSE ON 2014-10-18;")
예제 #17
0
 def test_from_close_no_expr(self):
     self.assertParse(
         qSelect(self.targets, qp.From(None, None, True, None)),
         "SELECT a, b FROM CLOSE;")