def test1(self): b = ws_sheets.Book(self.conf.Settings) b['0'][0, 0] = '2+2' self.assertEqual(b['0'][0, 0], 4) b['0'][0, 0] = '4' b['0'][0, 1] = 'sheet[0, 0]' self.assertEqual(b['0'][0, 1], 4) b['0'][0, 0] = '2' b['0'][0, 1] = '3' b['0'][0, 2] = 'sheet[0, 0:2]' print('cell 0,0 = ', b['0'][0, 0]) print('cell 0,1 = ', b['0'][0, 1]) print('cell 0,2 = ', b['0'][0, 2]) self.assertEqual(numpy.all(b['0'][0, 2] == numpy.array([2, 3])), True) self.assertEqual(b.context, 0) b['0'][0, 0] = 'sheet[0, 0]' self.assertEqual(repr(b['0'][0, 0].item()), "RuntimeError('recursion',)") b['0'][0, 0] = '' self.assertEqual(b['0'][0, 0].item(), None) b['0'][0, 0] = '4' b['1'][0, 0] = 'book[\'0\'][0, 0]' self.assertEqual(b['1'][0, 0], 4)
def test2(self): b = ws_sheets.Book(self.conf.Settings) b.set_cell('0', 0, 0, '1') b.set_cell('0', 1, 0, '2') b.set_cell('0', 2, 0, '3') b.set_cell('0', 3, 0, '4') b.set_cell('0', 4, 0, '5') b.set_cell('0', 0, 1, 'sum(sheet[0:5, 0])') self.assertEqual(b['0'][0, 1], 15)
def test_helper(self, settings): b = ws_sheets.Book(settings) s = b.sheets['0'] b.set_cell('0', 0, 0, "open('a.txt')") print(s.cells.cells[0, 0].value) b.set_cell('0', 0, 0, "open('a.txt', 'w').write('hello world')") print(s.cells.cells[0, 0].value) b.set_cell('0', 0, 0, "open('a.txt', 'r').read()") print(s.cells.cells[0, 0].value)
def test(self): b = ws_sheets.Book(ws_sheets.tests.conf.simple.Settings) b.set_script_pre('import os') b.do_all() print('output') print(b.script_pre.output) self.assertTrue(isinstance( b.script_pre.exec_exc, ws_sheets.exception.NotAllowedError)) b.set_script_pre("a = 1\n") b.set_cell('0', 0, 0, "a") self.assertEqual( b['0'][0, 0], 1)
def test_1(self): b = ws_sheets.Book(ws_sheets.tests.conf.simple.Settings) b.set_script_pre('book.do_all') b.do_all() print('output') print(b.script_pre.output) print('exc') print(repr(b.script_pre.exec_exc)) print(repr(b.script_pre.exec_exc.__class__)) assert isinstance(b.script_pre.exec_exc, ws_sheets.exception.NotAllowedError) b.set_script_pre('getattr(book,\'do_all\')') b.do_all() print('output') print(b.script_pre.output) print('exc') print(repr(b.script_pre.exec_exc)) print(repr(b.script_pre.exec_exc.__class__)) assert isinstance(b.script_pre.exec_exc, ws_sheets.exception.NotAllowedError) b.set_script_pre('object.__getattribute__(book,\'do_all\')') b.do_all() print('output') print(b.script_pre.output) print('exc') print(repr(b.script_pre.exec_exc)) print(repr(b.script_pre.exec_exc.__class__)) assert isinstance(b.script_pre.exec_exc, ws_sheets.exception.NotAllowedError)
def test(self): b = ws_sheets.Book(self.conf.Settings) s = b['0'] ######## print() b['0'][0, 0] = "dir(book)" c = s.cells.cells[0, 0] print('cell =', c) print(repr(c.value)) ######## print() b['0'][0, 0] = "dir(book.__eq__)" c = s.cells.cells[0, 0] #print(repr(b['0'][0, 0])) print('cell =', c) print(repr(c.value)) return self.assertEqual( repr(b['0'][0, 0].item()), 'NotAllowedError("cell not allowed to access \'__eq__\'",)') ######## print() b['0'][0, 0] = "book.test_func.__func__" c = s.cells.cells[0, 0] print('cell =', c) print(repr(c.value)) ######## print() b['0'][0, 0] = "book.test_func()" c = s.cells.cells[0, 0] print('cell =', c) print(repr(c.value)) ######## print() b['0'][0, 0] = "book.test_callable('hello','world')" c = s.cells.cells[0, 0] print('cell =', c) print(repr(c.value)) ######## print() b['0'][0, 0] = "book.test_callable.__call__.__func__" c = s.cells.cells[0, 0] print('cell =', c) print(repr(c.value)) if c.code is not None: code_analysis(c.code) return ######## print() b.set_cell( '0', 0, 0, "getattr(getattr(cellshelper, '__getitem__'), '__globals__').keys()" ) c = s.cells.cells[0, 0] print('cell =', c) print(s.cells.cells[0, 0].value) if c.code is not None: code_analysis(c.code) ######## print() b.set_cell('0', 0, 0, "dir(cellshelper)") c = s.cells.cells[0, 0] print('cell =', c) print(s.cells.cells[0, 0].value) if c.code is not None: code_analysis(c.code) ######## print() b.set_cell('0', 0, 0, "cellshelper._CellsHelper__book") c = s.cells.cells[0, 0] print('cell =', c) print(s.cells.cells[0, 0].value) if c.code is not None: code_analysis(c.code) ######## print() b.set_cell('0', 0, 0, "cellshelper[0,1]") c = s.cells.cells[0, 0] print('cell =', c) print(c.code.co_names) print(s.cells.cells[0, 0].value)