def test_constant(self):
     worksheet = Worksheet()
     worksheet[1, 2].formula = '3'
     calculate(worksheet, SANITY_CHECK_USERCODE % ('', ''), sentinel.private_key)
     self.assertEquals(worksheet.keys(), [(1, 2)])
     self.assertEquals(worksheet[(1, 2)].formula, '3')
     self.assertEquals(worksheet[(1, 2)].value, 3)
示例#2
0
 def test_constant(self):
     worksheet = Worksheet()
     worksheet[1, 2].formula = '3'
     calculate(worksheet, SANITY_CHECK_USERCODE % ('', ''),
               sentinel.private_key)
     self.assertEquals(worksheet.keys(), [(1, 2)])
     self.assertEquals(worksheet[(1, 2)].formula, '3')
     self.assertEquals(worksheet[(1, 2)].value, 3)
    def test_getitem_should_use_original_key_if_to_location_gives_none(self):
        ws = Worksheet()
        ws.to_location = Mock(return_value=(3, 4))

        ws[3, 4].formula = "hello"

        self.assertEquals(ws.to_location.call_args_list, [(((3, 4),), {})])
        self.assertEquals(ws.keys(), [(3, 4)])
        self.assertEquals(ws.values()[0].formula, "hello")
示例#4
0
    def test_setitem_on_locations_should_accept_cell_instances(self):
        ws = Worksheet()
        ws.to_location = Mock(return_value=(1, 2))
        cell = Cell()

        ws[3, 4] = cell

        self.assertEquals(ws.to_location.call_args_list, [(((3, 4), ), {})])
        self.assertEquals(ws.keys(), [(1, 2)])
    def test_setitem_on_locations_should_accept_cell_instances(self):
        ws = Worksheet()
        ws.to_location = Mock(return_value=(1, 2))
        cell = Cell()

        ws[3, 4] = cell

        self.assertEquals(ws.to_location.call_args_list, [(((3, 4),), {})])
        self.assertEquals(ws.keys(), [(1, 2)])
示例#6
0
    def test_getitem_should_use_to_location_result_if_it_is_not_none(self):
        ws = Worksheet()
        ws.to_location = Mock(return_value=(1, 2))

        ws[3, 4].formula = "hello"

        self.assertEquals(ws.to_location.call_args_list, [(((3, 4), ), {})])
        self.assertEquals(ws.keys(), [(1, 2)])
        self.assertEquals(ws.values()[0].formula, "hello")
示例#7
0
    def test_getitem_should_use_original_key_if_to_location_gives_none(self):
        ws = Worksheet()
        ws.to_location = Mock(return_value=(3, 4))

        ws[3, 4].formula = "hello"

        self.assertEquals(ws.to_location.call_args_list, [(((3, 4), ), {})])
        self.assertEquals(ws.keys(), [(3, 4)])
        self.assertEquals(ws.values()[0].formula, "hello")
    def test_getitem_should_use_to_location_result_if_it_is_not_none(self):
        ws = Worksheet()
        ws.to_location = Mock(return_value=(1, 2))

        ws[3, 4].formula = "hello"

        self.assertEquals(ws.to_location.call_args_list, [(((3, 4),), {})])
        self.assertEquals(ws.keys(), [(1, 2)])
        self.assertEquals(ws.values()[0].formula, "hello")
    def test_postformula_usercode(self):
        worksheet = Worksheet()
        worksheet[1, 1].formula = '=1'
        postformula_usercode = 'worksheet[1, 2].value = worksheet[1, 1].value + 1'

        calculate(worksheet, SANITY_CHECK_USERCODE % ('', postformula_usercode), sentinel.private_key)

        self.assertEquals(set(worksheet.keys()), set([(1, 1), (1, 2)]))
        self.assertEquals(worksheet[1, 1].value, 1)
        self.assertEquals(worksheet[1, 2].value, 2)
        self.assertEquals(worksheet[1, 1].formula, '=1')
        self.assertEquals(worksheet[1, 2].formula, None)
    def test_python_formulae(self):
        worksheet = Worksheet()
        worksheet[1, 1].python_formula = '1'
        worksheet[1, 2].python_formula = '2'
        worksheet[1, 3].python_formula = '1 + 2'

        calculate(worksheet, SANITY_CHECK_USERCODE % ('', ''), sentinel.private_key)

        self.assertEquals(set(worksheet.keys()), set([(1, 1), (1, 2), (1, 3)]))
        self.assertEquals(worksheet[1, 1].value, 1)
        self.assertEquals(worksheet[1, 2].value, 2)
        self.assertEquals(worksheet[1, 3].value, 3)
示例#11
0
    def test_python_formulae(self):
        worksheet = Worksheet()
        worksheet[1, 1].python_formula = '1'
        worksheet[1, 2].python_formula = '2'
        worksheet[1, 3].python_formula = '1 + 2'

        calculate(worksheet, SANITY_CHECK_USERCODE % ('', ''),
                  sentinel.private_key)

        self.assertEquals(set(worksheet.keys()), set([(1, 1), (1, 2), (1, 3)]))
        self.assertEquals(worksheet[1, 1].value, 1)
        self.assertEquals(worksheet[1, 2].value, 2)
        self.assertEquals(worksheet[1, 3].value, 3)
    def test_multiple_constants(self):
        worksheet = Worksheet()
        worksheet[1, 2].formula = '3'
        worksheet[3, 4].formula = '4+5'
        worksheet[2, 5].formula = 'blurgle'

        calculate(worksheet, SANITY_CHECK_USERCODE % ('', ''), sentinel.private_key)
        self.assertEquals(set(worksheet.keys()), set([(1, 2), (3, 4), (2, 5)]))
        self.assertEquals(worksheet[1, 2].formula, '3')
        self.assertEquals(worksheet[3, 4].formula, '4+5')
        self.assertEquals(worksheet[2, 5].formula, 'blurgle')
        self.assertEquals(worksheet[1, 2].value, 3)
        self.assertEquals(worksheet[3, 4].value, '4+5')
        self.assertEquals(worksheet[2, 5].value, 'blurgle')
示例#13
0
    def test_postformula_usercode(self):
        worksheet = Worksheet()
        worksheet[1, 1].formula = '=1'
        postformula_usercode = 'worksheet[1, 2].value = worksheet[1, 1].value + 1'

        calculate(worksheet,
                  SANITY_CHECK_USERCODE % ('', postformula_usercode),
                  sentinel.private_key)

        self.assertEquals(set(worksheet.keys()), set([(1, 1), (1, 2)]))
        self.assertEquals(worksheet[1, 1].value, 1)
        self.assertEquals(worksheet[1, 2].value, 2)
        self.assertEquals(worksheet[1, 1].formula, '=1')
        self.assertEquals(worksheet[1, 2].formula, None)
    def test_arithmetic(self):
        worksheet = Worksheet()
        worksheet[1, 2].formula = '=3'
        worksheet[3, 4].formula = '=4+5'
        worksheet[4, 4].formula = '=1/10'

        calculate(worksheet, SANITY_CHECK_USERCODE % ('', ''), sentinel.private_key)

        self.assertEquals(set(worksheet.keys()), set([(1, 2), (3, 4), (4, 4)]))
        self.assertEquals(worksheet[1, 2].value, 3)
        self.assertEquals(worksheet[3, 4].value, 9)
        self.assertEquals(worksheet[4, 4].value, 0.1)
        self.assertEquals(worksheet[1, 2].formula, '=3')
        self.assertEquals(worksheet[3, 4].formula, '=4+5')
        self.assertEquals(worksheet[4, 4].formula, '=1/10')
示例#15
0
    def test_multiple_constants(self):
        worksheet = Worksheet()
        worksheet[1, 2].formula = '3'
        worksheet[3, 4].formula = '4+5'
        worksheet[2, 5].formula = 'blurgle'

        calculate(worksheet, SANITY_CHECK_USERCODE % ('', ''),
                  sentinel.private_key)
        self.assertEquals(set(worksheet.keys()), set([(1, 2), (3, 4), (2, 5)]))
        self.assertEquals(worksheet[1, 2].formula, '3')
        self.assertEquals(worksheet[3, 4].formula, '4+5')
        self.assertEquals(worksheet[2, 5].formula, 'blurgle')
        self.assertEquals(worksheet[1, 2].value, 3)
        self.assertEquals(worksheet[3, 4].value, '4+5')
        self.assertEquals(worksheet[2, 5].value, 'blurgle')
    def test_preformula_usercode(self):
        worksheet = Worksheet()
        worksheet[1, 1].formula = '3'
        worksheet[1, 3].formula = '=A2 + 1'

        preformula_usercode = "worksheet[1, 2].value = worksheet[1, 1].value + 1"
        calculate(worksheet, SANITY_CHECK_USERCODE % (preformula_usercode, ''), sentinel.private_key)

        self.assertEquals(set(worksheet.keys()), set([(1, 1), (1, 2), (1, 3)]))
        self.assertEquals(worksheet[1, 1].value, 3)
        self.assertEquals(worksheet[1, 2].value, 4)
        self.assertEquals(worksheet[1, 3].value, 5)
        self.assertEquals(worksheet[1, 1].formula, '3')
        self.assertEquals(worksheet[1, 2].formula, None)
        self.assertEquals(worksheet[1, 3].formula, '=A2 + 1')
示例#17
0
    def test_preformula_usercode(self):
        worksheet = Worksheet()
        worksheet[1, 1].formula = '3'
        worksheet[1, 3].formula = '=A2 + 1'

        preformula_usercode = "worksheet[1, 2].value = worksheet[1, 1].value + 1"
        calculate(worksheet, SANITY_CHECK_USERCODE % (preformula_usercode, ''),
                  sentinel.private_key)

        self.assertEquals(set(worksheet.keys()), set([(1, 1), (1, 2), (1, 3)]))
        self.assertEquals(worksheet[1, 1].value, 3)
        self.assertEquals(worksheet[1, 2].value, 4)
        self.assertEquals(worksheet[1, 3].value, 5)
        self.assertEquals(worksheet[1, 1].formula, '3')
        self.assertEquals(worksheet[1, 2].formula, None)
        self.assertEquals(worksheet[1, 3].formula, '=A2 + 1')
示例#18
0
    def test_arithmetic(self):
        worksheet = Worksheet()
        worksheet[1, 2].formula = '=3'
        worksheet[3, 4].formula = '=4+5'
        worksheet[4, 4].formula = '=1/10'

        calculate(worksheet, SANITY_CHECK_USERCODE % ('', ''),
                  sentinel.private_key)

        self.assertEquals(set(worksheet.keys()), set([(1, 2), (3, 4), (4, 4)]))
        self.assertEquals(worksheet[1, 2].value, 3)
        self.assertEquals(worksheet[3, 4].value, 9)
        self.assertEquals(worksheet[4, 4].value, 0.1)
        self.assertEquals(worksheet[1, 2].formula, '=3')
        self.assertEquals(worksheet[3, 4].formula, '=4+5')
        self.assertEquals(worksheet[4, 4].formula, '=1/10')
    def test_preformula_usercode_functions(self):
        worksheet = Worksheet()
        worksheet[1, 1].formula = '1'
        worksheet[1, 2].formula = '=foo(3)'

        preformula_usercode = dedent('''
        def foo(value):
            return worksheet[1, 1].value + value
        ''')

        calculate(worksheet, SANITY_CHECK_USERCODE % (preformula_usercode, ''), sentinel.private_key)

        self.assertEquals(set(worksheet.keys()), set([(1, 1), (1, 2)]))
        self.assertEquals(worksheet[1, 1].value, 1)
        self.assertEquals(worksheet[1, 2].value, 4)
        self.assertEquals(worksheet[1, 1].formula, '1')
        self.assertEquals(worksheet[1, 2].formula, '=foo(3)')
示例#20
0
    def test_preformula_usercode_functions(self):
        worksheet = Worksheet()
        worksheet[1, 1].formula = '1'
        worksheet[1, 2].formula = '=foo(3)'

        preformula_usercode = dedent('''
        def foo(value):
            return worksheet[1, 1].value + value
        ''')

        calculate(worksheet, SANITY_CHECK_USERCODE % (preformula_usercode, ''),
                  sentinel.private_key)

        self.assertEquals(set(worksheet.keys()), set([(1, 1), (1, 2)]))
        self.assertEquals(worksheet[1, 1].value, 1)
        self.assertEquals(worksheet[1, 2].value, 4)
        self.assertEquals(worksheet[1, 1].formula, '1')
        self.assertEquals(worksheet[1, 2].formula, '=foo(3)')
    def test_formulae(self):
        worksheet = Worksheet()
        worksheet[1, 1].formula = '=1'
        worksheet[1, 2].formula = '=2'
        worksheet[1, 3].formula = '=A1 + A2'
        worksheet[1, 4].formula = '=DateTime(2000, 1, 2, 3, 4, 5)'

        calculate(worksheet, SANITY_CHECK_USERCODE % ('', ''), sentinel.private_key)

        self.assertEquals(set(worksheet.keys()), set([(1, 1), (1, 2), (1, 3), (1, 4)]))
        self.assertEquals(worksheet[1, 1].value, 1)
        self.assertEquals(worksheet[1, 2].value, 2)
        self.assertEquals(worksheet[1, 3].value, 3)
        self.assertEquals(worksheet[1, 4].value, datetime(2000, 1, 2, 3, 4, 5))
        self.assertEquals(worksheet[1, 1].formula, '=1')
        self.assertEquals(worksheet[1, 2].formula, '=2')
        self.assertEquals(worksheet[1, 3].formula, '=A1 + A2')
        self.assertEquals(worksheet[1, 4].formula, '=DateTime(2000, 1, 2, 3, 4, 5)')
示例#22
0
    def test_formulae(self):
        worksheet = Worksheet()
        worksheet[1, 1].formula = '=1'
        worksheet[1, 2].formula = '=2'
        worksheet[1, 3].formula = '=A1 + A2'
        worksheet[1, 4].formula = '=DateTime(2000, 1, 2, 3, 4, 5)'

        calculate(worksheet, SANITY_CHECK_USERCODE % ('', ''),
                  sentinel.private_key)

        self.assertEquals(set(worksheet.keys()),
                          set([(1, 1), (1, 2), (1, 3), (1, 4)]))
        self.assertEquals(worksheet[1, 1].value, 1)
        self.assertEquals(worksheet[1, 2].value, 2)
        self.assertEquals(worksheet[1, 3].value, 3)
        self.assertEquals(worksheet[1, 4].value, datetime(2000, 1, 2, 3, 4, 5))
        self.assertEquals(worksheet[1, 1].formula, '=1')
        self.assertEquals(worksheet[1, 2].formula, '=2')
        self.assertEquals(worksheet[1, 3].formula, '=A1 + A2')
        self.assertEquals(worksheet[1, 4].formula,
                          '=DateTime(2000, 1, 2, 3, 4, 5)')