Ejemplo n.º 1
0
    def test_loop(self):
        sample = testutil.parse_test_sample({
            "SCHEMA": [[
                1, "Table1",
                [
                    [31, "A", "Numeric", False, "", "", ""],
                    [31, "B", "Numeric", True, "$C", "", ""],
                    [32, "C", "Numeric", True, "$B", "", ""],
                ]
            ]],
            "DATA": {
                "Table1": [
                    ["id", "A"],
                    [1, 1],
                    [2, 2],
                    [3, 3],
                ]
            }
        })

        self.load_sample(sample)
        circle = objtypes.RaisedException(depend.CircularRefError())
        self.assertTableData('Table1',
                             data=[
                                 ['id', 'A', 'B', 'C'],
                                 [1, 1, circle, circle],
                                 [2, 2, circle, circle],
                                 [3, 3, circle, circle],
                             ])
Ejemplo n.º 2
0
    def test_cycle(self):
        sample = testutil.parse_test_sample({
            "SCHEMA": [[
                1, "Table1",
                [
                    [30, "A", "Numeric", False, "", "", ""],
                    [31, "Principal", "Numeric", True, "$Interest", "", ""],
                    [32, "Interest", "Numeric", True, "$Principal", "", ""],
                    [33, "A2", "Numeric", True, "$A", "", ""],
                ]
            ]],
            "DATA": {
                "Table1": [
                    ["id", "A"],
                    [1, 1],
                    [2, 2],
                    [3, 3],
                ]
            }
        })

        self.load_sample(sample)
        circle = objtypes.RaisedException(depend.CircularRefError())
        self.assertTableData('Table1',
                             data=[
                                 ['id', 'A', 'Principal', 'Interest', 'A2'],
                                 [1, 1, circle, circle, 1],
                                 [2, 2, circle, circle, 2],
                                 [3, 3, circle, circle, 3],
                             ])
Ejemplo n.º 3
0
    def test_cycle_and_reference(self):
        sample = testutil.parse_test_sample({
            "SCHEMA": [
                [
                    2, "ATable",
                    [
                        [32, "A", "Ref:ZTable", False, "", "", ""],
                        [33, "B", "Numeric", True, "$A.B", "", ""],
                    ]
                ],
                [
                    1, "ZTable",
                    [
                        [31, "A", "Numeric", False, "", "", ""],
                        [31, "B", "Numeric", True, "$B", "", ""],
                    ]
                ],
            ],
            "DATA": {
                "ATable": [
                    ["id", "A"],
                    [1, 1],
                    [2, 2],
                    [3, 3],
                ],
                "ZTable": [
                    ["id", "A"],
                    [1, 6],
                    [2, 7],
                    [3, 8],
                ]
            }
        })

        self.load_sample(sample)
        circle = objtypes.RaisedException(depend.CircularRefError())
        self.assertTableData('ATable',
                             data=[
                                 ['id', 'A', 'B'],
                                 [1, 1, circle],
                                 [2, 2, circle],
                                 [3, 3, circle],
                             ])
        self.assertTableData('ZTable',
                             data=[
                                 ['id', 'A', 'B'],
                                 [1, 6, circle],
                                 [2, 7, circle],
                                 [3, 8, circle],
                             ])
Ejemplo n.º 4
0
    def test_cumulative_formula_with_references(self):
        top = 100
        formula = "max($Prev.Principal + $Prev.Interest, 1000)"
        sample = testutil.parse_test_sample({
            "SCHEMA": [[
                1, "Table1",
                [
                    [41, "Prev", "Ref:Table1", True, "$id - 1", "", ""],
                    [42, "Principal", "Numeric", True, formula, "", ""],
                    [
                        43, "Interest", "Numeric", True,
                        "int($Principal * 0.1)", "", ""
                    ],
                ]
            ],
                       [
                           2, "Readout",
                           [
                               [
                                   46, "LastPrincipal", "Numeric", True,
                                   "Table1.lookupOne(id=%d).Principal" % top,
                                   "", ""
                               ],
                           ]
                       ]],
            "DATA": {
                "Table1": [["id"]] + [[r] for r in range(1, top + 1)],
                "Readout": [["id"], [1]],
            }
        })

        self.load_sample(sample)
        self.assertTableData('Readout',
                             data=[
                                 ['id', 'LastPrincipal'],
                                 [1, 12494908.0],
                             ])

        self.modify_column("Table1",
                           "Prev",
                           formula="$id - 1 if $id > 1 else 100")
        self.assertTableData(
            'Readout',
            data=[
                ['id', 'LastPrincipal'],
                [1, objtypes.RaisedException(depend.CircularRefError())],
            ])
Ejemplo n.º 5
0
 def test_catch_all_in_formula(self):
     sample = testutil.parse_test_sample({
         "SCHEMA": [
             [
                 1, "Table1",
                 [
                     [51, "A", "Numeric", False, "", "", ""],
                     [
                         52, "B1", "Numeric", True,
                         "try:\n  return $A+$C\nexcept:\n  return 42", "",
                         ""
                     ],
                     [
                         53, "B2", "Numeric", True,
                         "try:\n  return $D+None\nexcept:\n  return 42", "",
                         ""
                     ],
                     [
                         54, "B3", "Numeric", True,
                         "try:\n  return $A+$B4+$D\nexcept:\n  return 42",
                         "", ""
                     ],
                     [
                         55, "B4", "Numeric", True,
                         "try:\n  return $A+$B3+$D\nexcept:\n  return 42",
                         "", ""
                     ],
                     [
                         56, "B5", "Numeric", True,
                         "try:\n  return $E+1\nexcept:\n  raise Exception('monkeys!')",
                         "", ""
                     ],
                     [
                         56, "B6", "Numeric", True,
                         "try:\n  return $F+1\nexcept Exception as e:\n  e.node = e.row_id = 'monkey'",
                         "", ""
                     ],
                     [57, "C", "Numeric", False, "", "", ""],
                     [58, "D", "Numeric", True, "$A", "", ""],
                     [59, "E", "Numeric", True, "$A", "", ""],
                     [59, "F", "Numeric", True, "$A", "", ""],
                 ]
             ],
         ],
         "DATA": {
             "Table1": [["id", "A", "C"], [1, 1, 2], [2, 20, 10]],
         }
     })
     self.load_sample(sample)
     circle = objtypes.RaisedException(depend.CircularRefError())
     # B4 is a subtle case.  B3 and B4 refer to each other.  B3 is recomputed first,
     # and cells evaluate to a CircularRefError.  Now B3 has a value, so B4 can be
     # evaluated, and results in 42 when addition of an integer and an exception value
     # fails.
     self.assertTableData(
         'Table1',
         data=[
             [
                 'id', 'A', 'B1', 'B2', 'B3', 'B4', 'B5', 'B6', 'C', 'D',
                 'E', 'F'
             ],
             [1, 1, 3, 42, circle, 42, 2, 2, 2, 1, 1, 1],
             [2, 20, 30, 42, circle, 42, 21, 21, 10, 20, 20, 20],
         ])