Esempio n. 1
0
    def test_returns_graph_and_leaf_nodes(self):
        worksheet = Worksheet()
        worksheet[1, 1].formula = '=A2 + B2'
        worksheet[1, 2].formula = '=A3'
        worksheet[2, 2].formula = '=B3'
        worksheet[1, 3].formula = '=1'
        worksheet[2, 3].formula = '1'
        worksheet[3, 3].python_formula = '1'

        graph, leaves = build_dependency_graph(worksheet)

        self.maxDiff = None
        self.assertEquals(
            graph, {
                (1, 1): Node(
                    (1, 1), children=set([(1, 2), (2, 2)]), parents=set()),
                (1, 2): Node(
                    (1, 2), children=set([(1, 3)]), parents=set([(1, 1)])),
                (2, 2): Node((2, 2), children=set(), parents=set([(1, 1)])),
                (1, 3): Node((1, 3), children=set(), parents=set([(1, 2)])),
                (3, 3): Node((3, 3), children=set(), parents=set()),
            })
        self.assertEquals(set(leaves), set([(1, 3), (2, 2), (3, 3)]))

        worksheet[1, 2].formula = '=A3 + B3'
        graph, leaves = build_dependency_graph(worksheet)

        self.assertEquals(
            graph, {
                (1, 1):
                Node(
                    (1, 1),
                    children=set([(1, 2), (2, 2)]),
                    parents=set(),
                ),
                (1, 2):
                Node(
                    (1, 2),
                    children=set([(1, 3)]),
                    parents=set([(1, 1)]),
                ),
                (2, 2):
                Node((2, 2), children=set(), parents=set([(1, 1)])),
                (1, 3):
                Node((1, 3), children=set(), parents=set([(1, 2)])),
                (3, 3):
                Node((3, 3), children=set(), parents=set()),
            })
        self.assertEquals(set(leaves), set([(1, 3), (2, 2), (3, 3)]))
    def test_puts_errors_on_cells_in_cycles_and_omits_them_from_graph(self, mock_report_cell_error):
        mock_report_cell_error.side_effect = report_cell_error
        worksheet = Worksheet()
        worksheet[1, 1].formula = '=A2'
        worksheet[1, 2].formula = '=A1'
        worksheet[1, 3].formula = '=A1'
        worksheet[1, 4].formula = '=A5'
        worksheet[1, 5].formula = '=5'

        graph, leaves = build_dependency_graph(worksheet)
        self.assertEquals(
            graph,
            {
                (1, 3): Node((1, 3), children=set(), parents=set()),
                (1, 4): Node((1, 4), children=set([(1, 5)]), parents=set()),
                (1, 5): Node((1, 5), children=set(), parents=set([(1, 4)])),
            }
        )
        self.assertEquals(leaves, [(1, 5), (1, 3)])
        a1_cycle_error = CycleError([(1, 2), (1, 1), (1, 2)])
        self.assertEquals(
            mock_report_cell_error.call_args_list,
            [
                call(worksheet, (1, 2), a1_cycle_error),
                call(worksheet, (1, 1), a1_cycle_error),
            ]
        )
Esempio n. 3
0
    def test_is_robust_against_references_to_empty_cells(self):
        worksheet = Worksheet()
        worksheet[1, 1].formula = '=A2'

        # NB we're making sure that this call doesn't raise an error
        # because the cell A2 is created in the dictionary while we're
        # iterating over it.
        graph, leaves = build_dependency_graph(worksheet)

        self.maxDiff = None
        self.assertEquals(
            graph, {(1, 1): Node((1, 1), children=set(), parents=set())})
        self.assertEquals(leaves, [(1, 1)])
    def test_is_robust_against_references_to_empty_cells(self):
        worksheet = Worksheet()
        worksheet[1, 1].formula = '=A2'

        # NB we're making sure that this call doesn't raise an error
        # because the cell A2 is created in the dictionary while we're
        # iterating over it.
        graph, leaves = build_dependency_graph(worksheet)

        self.maxDiff = None
        self.assertEquals(
            graph,
            {
                (1, 1): Node(
                    (1, 1),
                    children=set(),
                    parents=set()
                )
            }
        )
        self.assertEquals(leaves, [(1, 1)])
Esempio n. 5
0
    def test_puts_errors_on_cells_in_cycles_and_omits_them_from_graph(
            self, mock_report_cell_error):
        mock_report_cell_error.side_effect = report_cell_error
        worksheet = Worksheet()
        worksheet[1, 1].formula = '=A2'
        worksheet[1, 2].formula = '=A1'
        worksheet[1, 3].formula = '=A1'
        worksheet[1, 4].formula = '=A5'
        worksheet[1, 5].formula = '=5'

        graph, leaves = build_dependency_graph(worksheet)
        self.assertEquals(
            graph, {
                (1, 3): Node((1, 3), children=set(), parents=set()),
                (1, 4): Node((1, 4), children=set([(1, 5)]), parents=set()),
                (1, 5): Node((1, 5), children=set(), parents=set([(1, 4)])),
            })
        self.assertEquals(leaves, [(1, 5), (1, 3)])
        a1_cycle_error = CycleError([(1, 2), (1, 1), (1, 2)])
        self.assertEquals(mock_report_cell_error.call_args_list, [
            call(worksheet, (1, 2), a1_cycle_error),
            call(worksheet, (1, 1), a1_cycle_error),
        ])
    def test_returns_graph_and_leaf_nodes(self):
        worksheet = Worksheet()
        worksheet[1, 1].formula = '=A2 + B2'
        worksheet[1, 2].formula = '=A3'
        worksheet[2, 2].formula = '=B3'
        worksheet[1, 3].formula = '=1'
        worksheet[2, 3].formula = '1'
        worksheet[3, 3].python_formula = '1'

        graph, leaves = build_dependency_graph(worksheet)

        self.maxDiff = None
        self.assertEquals(
            graph,
            {
                (1, 1): Node(
                    (1, 1),
                    children=set([(1, 2), (2, 2)]),
                    parents=set()
                ),
                (1, 2): Node(
                    (1, 2),
                    children=set([(1, 3)]),
                    parents=set([(1, 1)])
                ),
                (2, 2): Node(
                    (2, 2),
                    children=set(),
                    parents=set([(1, 1)])
                ),
                (1, 3): Node(
                    (1, 3),
                    children=set(),
                    parents=set([(1, 2)])
                ),
                (3, 3): Node(
                    (3, 3),
                    children=set(),
                    parents=set()
                ),
            }
        )
        self.assertEquals(set(leaves), set([(1, 3), (2, 2), (3, 3)]))

        worksheet[1, 2].formula = '=A3 + B3'
        graph, leaves = build_dependency_graph(worksheet)

        self.assertEquals(graph, {
            (1, 1): Node(
                (1, 1),
                children=set([(1, 2), (2, 2)]),
                parents=set(),
            ),
            (1, 2): Node(
                (1, 2),
                children=set([(1, 3)]),
                parents=set([(1, 1)]),
            ),
            (2, 2): Node(
                (2, 2),
                children=set(),
                parents=set([(1, 1)])
            ),
            (1, 3): Node(
                (1, 3),
                children=set(),
                parents=set([(1, 2)])
            ),
            (3, 3): Node(
                (3, 3),
                children=set(),
                parents=set()
            ),
        })
        self.assertEquals(set(leaves), set([(1, 3), (2, 2), (3, 3)]))