Esempio n. 1
0
 def test_get_parse_tree_dependencies_should_not_return_locations_for_deleted_references(
         self):
     self.assertEquals(
         get_dependencies_from_parse_tree(parse("=#Deleted!")), [])
     self.assertEquals(
         get_dependencies_from_parse_tree(parse("=#Deleted! + A2")),
         [(1, 2)])
    def test_rewrite_should_raise_deleted_cell_reference_error_when_appropriate(self):
        with self.assertRaises(FormulaError) as mgr:
            rewrite(parse('=#Deleted!')).flatten()
        self.assertEquals(str(mgr.exception), "#Deleted! cell reference in formula")

        with self.assertRaises(FormulaError) as mgr:
            rewrite(parse('=sum(#Deleted!:B1)'))
        self.assertEquals(str(mgr.exception), "#Deleted! cell reference in formula")
Esempio n. 3
0
 def test_get_parse_tree_dependencies_should_not_return_locations_for_worksheet_references(
         self):
     for expression in ("=<Sheet1>", "=<Sheet1>.Bounds",
                        "=<Sheet1> + <Sheet2>"):
         self.assertEquals(
             get_dependencies_from_parse_tree(parse(expression)), [])
     self.assertEquals(
         get_dependencies_from_parse_tree(parse("=<Sheet1> + A2")),
         [(1, 2)])
Esempio n. 4
0
 def test_get_parse_tree_dependencies_should_not_return_locations_for_invalid_references_in_cell_ranges(
         self):
     self.assertEquals(
         get_dependencies_from_parse_tree(parse("=#Invalid!:A2")), [])
     self.assertEquals(
         get_dependencies_from_parse_tree(parse("=A2:#Invalid!")), [])
     self.assertEquals(
         get_dependencies_from_parse_tree(parse("=#Invalid!:#Invalid!")),
         [])
Esempio n. 5
0
    def test_rewrite_should_translate_dictionary_arrow_to_colon(self):
        self.assertEquals(
            rewrite(parse('={"key"->"value"}')).flatten(), '={"key":"value"}')

        self.assertEquals(
            rewrite(parse('={"key"  ->"value"}')).flatten(),
            '={"key"  :"value"}')

        self.assertEquals(
            rewrite(parse('={"key"->  "value"}')).flatten(),
            '={"key":"value"}')
Esempio n. 6
0
    def test_rewrite_should_raise_deleted_cell_reference_error_when_appropriate(
            self):
        with self.assertRaises(FormulaError) as mgr:
            rewrite(parse('=#Deleted!')).flatten()
        self.assertEquals(str(mgr.exception),
                          "#Deleted! cell reference in formula")

        with self.assertRaises(FormulaError) as mgr:
            rewrite(parse('=sum(#Deleted!:B1)'))
        self.assertEquals(str(mgr.exception),
                          "#Deleted! cell reference in formula")
Esempio n. 7
0
    def test_rewrite_should_translate_lambda_arrow_to_colon(self):
        self.assertEquals(
            rewrite(parse('=lambda x->  x')).flatten(), '=lambda x:x')

        self.assertEquals(
            rewrite(parse('=lambda   x-> x')).flatten(), '=lambda   x:x')

        self.assertEquals(
            rewrite(parse('=lambda x  -> x')).flatten(), '=lambda x  :x')

        self.assertEquals(
            rewrite(parse('=lambda -> x')).flatten(), '=lambda :x')
Esempio n. 8
0
 def test_get_parse_tree_dependencies_should_return_cellrange_deps(self):
     self.assertItemsEqual(
         get_dependencies_from_parse_tree(parse('=a2:b3')), [(1, 2), (1, 3),
                                                             (2, 2),
                                                             (2, 3)])
     self.assertItemsEqual(
         get_dependencies_from_parse_tree(parse('=b3:a2')), [(1, 2), (1, 3),
                                                             (2, 2),
                                                             (2, 3)])
     self.assertItemsEqual(
         get_dependencies_from_parse_tree(parse('=a3:b2')), [(1, 2), (1, 3),
                                                             (2, 2),
                                                             (2, 3)])
 def test_get_parse_tree_dependencies_should_return_cellrange_deps(self):
     self.assertItemsEqual(
         get_dependencies_from_parse_tree(parse('=a2:b3')),
         [(1, 2), (1, 3), (2, 2), (2, 3)]
     )
     self.assertItemsEqual(
         get_dependencies_from_parse_tree(parse('=b3:a2')),
         [(1, 2), (1, 3), (2, 2), (2, 3)]
     )
     self.assertItemsEqual(
         get_dependencies_from_parse_tree(parse('=a3:b2')),
         [(1, 2), (1, 3), (2, 2), (2, 3)]
     )
    def test_rewrite_should_translate_dictionary_arrow_to_colon(self):
        self.assertEquals(
            rewrite(parse('={"key"->"value"}')).flatten(),
            '={"key":"value"}'
            )

        self.assertEquals(
            rewrite(parse('={"key"  ->"value"}')).flatten(),
            '={"key"  :"value"}'
            )

        self.assertEquals(
            rewrite(parse('={"key"->  "value"}')).flatten(),
            '={"key":"value"}'
            )
Esempio n. 11
0
 def test_produces_correct_python(self):
     self.assertEquals(
         get_python_formula_from_parse_tree(
             parse('=[x * A1 for x in range(5)]')),
         '[x * worksheet[(1,1)].value for x in range(5)]')
     self.assertEquals(
         get_python_formula_from_parse_tree(
             parse('=[x in A1:B3 for x in range(5)]')),
         '[x in CellRange(worksheet,(1,1),(2,3)) for x in range(5)]')
     self.assertEquals(
         get_python_formula_from_parse_tree(parse('={1 -> B1}')),
         '{1 :worksheet[(2,1)].value }')
     self.assertEquals(
         get_python_formula_from_parse_tree(
             parse('=(lambda x -> C1 * x)(2)')),
         '(lambda x :worksheet[(3,1)].value * x)(2)')
    def test_rewrite_should_translate_lambda_arrow_to_colon(self):
        self.assertEquals(
            rewrite(parse('=lambda x->  x')).flatten(),
            '=lambda x:x'
        )

        self.assertEquals(
            rewrite(parse('=lambda   x-> x')).flatten(),
            '=lambda   x:x'
            )

        self.assertEquals(
            rewrite(parse('=lambda x  -> x')).flatten(),
            '=lambda x  :x'
            )

        self.assertEquals(
            rewrite(parse('=lambda -> x')).flatten(),
            '=lambda :x'
            )
 def test_produces_correct_python(self):
     self.assertEquals(
         get_python_formula_from_parse_tree(parse(
             '=[x * A1 for x in range(5)]'
         )),
         '[x * worksheet[(1,1)].value for x in range(5)]'
     )
     self.assertEquals(
         get_python_formula_from_parse_tree(parse(
             '=[x in A1:B3 for x in range(5)]'
         )),
         '[x in CellRange(worksheet,(1,1),(2,3)) for x in range(5)]'
     )
     self.assertEquals(
         get_python_formula_from_parse_tree(parse('={1 -> B1}')),
         '{1 :worksheet[(2,1)].value }'
     )
     self.assertEquals(
         get_python_formula_from_parse_tree(parse('=(lambda x -> C1 * x)(2)')),
         '(lambda x :worksheet[(3,1)].value * x)(2)'
     )
 def test_slicing_in_formulae(self):
     self.assertEquals(
         rewrite(parse('=p[1->]')).flatten(),
         '=p[1:]'
     )
     self.assertEquals(
         rewrite(parse('=p[->6]')).flatten(),
         '=p[:6]'
     )
     self.assertEquals(
         rewrite(parse('=p[1->6]')).flatten(),
         '=p[1:6]'
     )
     self.assertEquals(
         rewrite(parse('=p[1->6->3]')).flatten(),
         '=p[1:6:3]'
     )
     self.assertEquals(
         rewrite(parse('=p[1->->3]')).flatten(),
         '=p[1::3]'
     )
 def test_converts_cell_references_and_adds_space(self):
     self.assertEquals(
         get_python_formula_from_parse_tree(parse('=A1')),
         "worksheet[(1,1)].value "
     )
 def test_converts_formula_starting_with_equals(self):
     self.assertEquals(get_python_formula_from_parse_tree(parse('=1')), "1")
     self.assertEquals(get_python_formula_from_parse_tree(parse('=1+2')), "1+2")
Esempio n. 17
0
 def test_get_parse_tree_dependencies_should_return_empty_list_when_no_cell_refs(
         self):
     tree = parse("=1+2")
     self.assertEquals(get_dependencies_from_parse_tree(tree), [])
 def test_get_parse_tree_dependencies_should_not_return_locations_for_worksheet_references(self):
     for expression in ("=<Sheet1>", "=<Sheet1>.Bounds", "=<Sheet1> + <Sheet2>"):
         self.assertEquals(get_dependencies_from_parse_tree(parse(expression)), [])
     self.assertEquals(get_dependencies_from_parse_tree(parse("=<Sheet1> + A2")), [(1, 2)])
 def test_get_parse_tree_dependencies_should_not_return_locations_for_deleted_references_in_cell_ranges(self):
     self.assertEquals(get_dependencies_from_parse_tree(parse("=#Deleted!:A2")), [])
     self.assertEquals(get_dependencies_from_parse_tree(parse("=A2:#Deleted!")), [])
     self.assertEquals(get_dependencies_from_parse_tree(parse("=#Deleted!:#Deleted!")), [])
 def test_get_parse_tree_dependencies_should_not_return_locations_for_invalid_references(self):
     self.assertEquals(get_dependencies_from_parse_tree(parse("=#Invalid!")), [])
     self.assertEquals(get_dependencies_from_parse_tree(parse("=#Invalid! + A2")), [(1, 2)])
Esempio n. 21
0
 def test_converts_formula_starting_with_equals(self):
     self.assertEquals(get_python_formula_from_parse_tree(parse('=1')), "1")
     self.assertEquals(get_python_formula_from_parse_tree(parse('=1+2')),
                       "1+2")
 def test_get_parse_tree_dependencies_should_return_locations_disregarding_worksheet_names(self):
     tree = parse("=Sheet1!A3")
     self.assertEquals(get_dependencies_from_parse_tree(tree), [(1, 3)])
 def test_get_parse_tree_dependencies_should_return_locations_for_simple_expression_with_case_mismatch(self):
     tree = parse("=a1+A2")
     self.assertEquals(get_dependencies_from_parse_tree(tree), [(1, 1), (1, 2)])
 def test_get_parse_tree_dependencies_should_return_empty_list_when_no_cell_refs(self):
     tree = parse("=1+2")
     self.assertEquals(get_dependencies_from_parse_tree(tree), [])
Esempio n. 25
0
 def test_get_parse_tree_dependencies_should_return_locations_for_simple_expression_with_case_mismatch(
         self):
     tree = parse("=a1+A2")
     self.assertEquals(get_dependencies_from_parse_tree(tree), [(1, 1),
                                                                (1, 2)])
Esempio n. 26
0
 def test_get_parse_tree_dependencies_should_return_locations_disregarding_worksheet_names(
         self):
     tree = parse("=Sheet1!A3")
     self.assertEquals(get_dependencies_from_parse_tree(tree), [(1, 3)])
Esempio n. 27
0
 def test_get_parse_tree_dependencies_should_return_locations_used_for_function_calls_and_arguments(
         self):
     tree = parse("=A2(a3)")
     self.assertEquals(get_dependencies_from_parse_tree(tree), [(1, 2),
                                                                (1, 3)])
Esempio n. 28
0
 def test_slicing_in_formulae(self):
     self.assertEquals(rewrite(parse('=p[1->]')).flatten(), '=p[1:]')
     self.assertEquals(rewrite(parse('=p[->6]')).flatten(), '=p[:6]')
     self.assertEquals(rewrite(parse('=p[1->6]')).flatten(), '=p[1:6]')
     self.assertEquals(rewrite(parse('=p[1->6->3]')).flatten(), '=p[1:6:3]')
     self.assertEquals(rewrite(parse('=p[1->->3]')).flatten(), '=p[1::3]')
 def test_get_parse_tree_dependencies_should_return_locations_used_for_function_calls_and_arguments(self):
     tree = parse("=A2(a3)")
     self.assertEquals(get_dependencies_from_parse_tree(tree), [(1, 2), (1, 3)])
Esempio n. 30
0
 def test_converts_cell_references_and_adds_space(self):
     self.assertEquals(get_python_formula_from_parse_tree(parse('=A1')),
                       "worksheet[(1,1)].value ")