def test_from_code_array(self): """Test from_code_array method""" self.xls_in.to_code_array() wb = xlwt.Workbook() xls_out = Xls(self.code_array, wb) worksheets = [] xls_out._shape2xls(worksheets) xls_out._code2xls(worksheets) xls_out._row_heights2xls(worksheets) self.write_xls_out(xls_out, wb, "_col_widths2xls", worksheets) new_code_array = CodeArray((1000, 100, 3)) xls_outfile = xlrd.open_workbook(self.xls_outfile_path, formatting_info=True) xls_out = Xls(new_code_array, xls_outfile) xls_out.to_code_array() assert self.code_array.shape == new_code_array.shape assert self.code_array.macros == new_code_array.macros assert self.code_array.dict_grid == new_code_array.dict_grid # There may be additional standard heights in copy --> 1 way test for height in self.code_array.row_heights: assert height in new_code_array.row_heights assert self.code_array.col_widths == new_code_array.col_widths # Clean up the test dir os.remove(self.xls_outfile_path)
def __init__(self, main_window, *args, **kwargs): S = kwargs.pop("S") self.main_window = main_window self._states() self.interfaces = GuiInterfaces(self.main_window) if S is None: dimensions = kwargs.pop("dimensions") else: dimensions = S.shape kwargs.pop("dimensions") wx.grid.Grid.__init__(self, main_window, *args, **kwargs) self.SetDefaultCellBackgroundColour(wx.Colour(255, 255, 255, 255)) # Cursor position on entering selection mode self.sel_mode_cursor = None # Set multi line editor self.SetDefaultEditor(GridCellEditor(main_window)) # Create new grid if S is None: self.code_array = CodeArray(dimensions) post_command_event(self, self.GridActionNewMsg, shape=dimensions) else: self.code_array = S _grid_table = GridTable(self, self.code_array) self.SetTable(_grid_table, True) # Grid renderer draws the grid self.grid_renderer = GridRenderer(self.code_array) self.SetDefaultRenderer(self.grid_renderer) # Context menu for quick access of important functions self.contextmenu = ContextMenu(parent=self) # Handler classes contain event handler methods self.handlers = GridEventHandlers(self) self.cell_handlers = GridCellEventHandlers(self) # Grid actions self.actions = AllGridActions(self) # Layout and bindings self._layout() self._bind() # Update toolbars self.update_entry_line() self.update_attribute_toolbar() # Focus on grid so that typing can start immediately self.SetFocus()
def setup_method(self, method): """Creates Pys class with code_array and temporary test.pys file""" # All data structures are initially empty # The test file pys_file has entries in each category self.code_array = CodeArray((1000, 100, 3)) self.pys_infile = bz2.BZ2File(TESTPATH + "pys_test1.pys") self.pys_outfile_path = TESTPATH + "pys_test2.pys" self.pys_in = Pys(self.code_array, self.pys_infile)
def test_slicing(self): """Unit test for __getitem__ and __setitem__""" #Test for item getting, slicing, basic evaluation correctness shape = self.code_array.shape x_list = [0, shape[0]-1] y_list = [0, shape[1]-1] z_list = [0, shape[2]-1] for x, y, z in zip(x_list, y_list, z_list): assert self.code_array[x, y, z] is None self.code_array[:x, :y, :z] self.code_array[:x:2, :y:2, :z:-1] get_shape = numpy.array(self.code_array[:, :, :]).shape orig_shape = self.code_array.shape assert get_shape == orig_shape gridsize = 100 filled_grid = CodeArray((gridsize, 10, 1)) for i in [-2**99, 2**99, 0]: for j in xrange(gridsize): filled_grid[j, 0, 0] = str(i) filled_grid[j, 1, 0] = str(i) + '+' + str(j) filled_grid[j, 2, 0] = str(i) + '*' + str(j) for j in xrange(gridsize): assert filled_grid[j, 0, 0] == i assert filled_grid[j, 1, 0] == i + j assert filled_grid[j, 2, 0] == i * j for j, funcname in enumerate(['int', 'math.ceil', 'fractions.Fraction']): filled_grid[0, 0, 0] = "fractions = __import__('fractions')" filled_grid[0, 0, 0] filled_grid[1, 0, 0] = "math = __import__('math')" filled_grid[1, 0, 0] filled_grid[j, 3, 0] = funcname + ' (' + str(i) + ')' #res = eval(funcname + "(" + "i" + ")") assert filled_grid[j, 3, 0] == eval(funcname + "(" + "i" + ")") #Test X, Y, Z for i in xrange(10): self.code_array[i, 0, 0] = str(i) assert [self.code_array((i, 0, 0)) for i in xrange(10)] == \ map(str, xrange(10)) assert [self.code_array[i, 0, 0] for i in xrange(10)] == range(10) # Test cycle detection filled_grid[0, 0, 0] = "numpy.arange(0, 10, 0.1)" filled_grid[1, 0, 0] = "sum(S[0,0,0])" assert filled_grid[1, 0, 0] == sum(numpy.arange(0, 10, 0.1))
def setup_method(self, method): """Creates Xls class with code_array and temporary test.xls file""" # All data structures are initially empty # The test file xls_file has entries in each category self.top_window = wx.Frame(None, -1) wx.GetApp().SetTopWindow(self.top_window) self.code_array = CodeArray((1000, 100, 3)) self.xls_infile = xlrd.open_workbook(TESTPATH + "xls_test1.xls", formatting_info=True) self.xls_outfile_path = TESTPATH + "xls_test2.xls" self.xls_in = Xls(self.code_array, self.xls_infile)
def setup_method(self, method): """Creates empty DataArray""" self.code_array = CodeArray((100, 10, 3))