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")
예제 #2
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")
예제 #3
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"}')
예제 #4
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')
    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"}'
            )
    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_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]'
     )
예제 #8
0
    def test_rewrite_parse_node_should_return_parse_node_with_children_rewritten(
            self, mock_recursive_rewrite):
        node_type = "junk node type"
        children = [ParseNode(node_type, None), ParseNode(node_type, None)]
        input = ParseNode(node_type, children)

        mock_recursive_results = [object(), object()]

        def mock_recursive_results_generator_func(*args):
            yield mock_recursive_results[0]
            yield mock_recursive_results[1]

        mock_recursive_results_generator = mock_recursive_results_generator_func(
        )
        mock_recursive_rewrite.side_effect = lambda *_: mock_recursive_results_generator.next(
        )

        self.assertEquals(id(rewrite(input)), id(input))
        self.assertEquals(mock_recursive_rewrite.call_args_list,
                          [((children[0], ), {}), ((children[1], ), {})])
        self.assertEquals(input.children, mock_recursive_results)
    def test_rewrite_parse_node_should_return_parse_node_with_children_rewritten(self, mock_recursive_rewrite):
        node_type = "junk node type"
        children = [ParseNode(node_type, None), ParseNode(node_type, None)]
        input = ParseNode(node_type, children)

        mock_recursive_results = [object(), object()]
        def mock_recursive_results_generator_func(*args):
            yield mock_recursive_results[0]
            yield mock_recursive_results[1]
        mock_recursive_results_generator = mock_recursive_results_generator_func()
        mock_recursive_rewrite.side_effect = lambda *_: mock_recursive_results_generator.next()

        self.assertEquals(id(rewrite(input)), id(input))
        self.assertEquals(
            mock_recursive_rewrite.call_args_list,
            [
                ((children[0],), {}),
                ((children[1],), {})
            ]
        )
        self.assertEquals(
            input.children,
            mock_recursive_results
        )
 def test_rewrite_string_should_return_object_unchanged(self):
     input = "Hello, world"
     self.assertEquals(rewrite(input), input)
 def test_rewrite_cell_reference_should_return_appropriate_tree(self):
     self.assertEquals(
         rewrite(FLCellReference(["A2"])).flatten(),
         'worksheet[(1,2)].value '
     )
예제 #12
0
 def test_rewrite_cell_reference_should_return_appropriate_tree(self):
     self.assertEquals(
         rewrite(FLCellReference(["A2"])).flatten(),
         'worksheet[(1,2)].value ')
예제 #13
0
 def test_rewrite_string_should_return_object_unchanged(self):
     input = "Hello, world"
     self.assertEquals(rewrite(input), input)
예제 #14
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]')