def test_write_all(self): top = Container('top') child = Container('child', top, attribute=[0]) child2 = Container('child2', attribute=1) top.add_child('child', child2) fhandle = open('container_test.dat', 'w') top.write_all(fhandle) fhandle.close() fhandle = open('container_test.dat', 'r') line1 = fhandle.readline() line1 = line1.strip().split('=') self.assertEqual(line1[0].strip(), 'child') self.assertEqual(line1[1].strip(), '0') line2 = fhandle.readline() line2 = line2.strip().split('=') self.assertEqual(line2[0].strip(), 'child2') self.assertEqual(line2[1].strip(), '1') fhandle.close() os.remove('container_test.dat')
def createContainers(self): self.containers["feedback"] = Container([0, 0], [5, 5]) self.containers["feedback"].addElement(self.elements["scale"]) self.containers["feedback"].addElement(self.elements["fps"]) self.containers["feedback"].addElement(self.elements["mousePos"]) self.containers["feedback"].setPosition("topRight") self.containers["nodeBox"] = Container([0, 0], [5, 5]) self.containers["nodeBox"].addElement(self.elements["nPos"]) self.containers["nodeBox"].addElement(self.elements["nValue"]) self.containers["nodeBox"].addElement(self.elements["nConnectionX"]) self.containers["nodeBox"].addElement(self.elements["nConnectionY"]) self.containers["nodeBox"].setPosition("right") self.containers["nodeBox"].hide() self.containers["outputBox"] = Container([0, 0], [5, 5]) self.containers["outputBox"].addElement(self.elements["oInput"]) self.containers["outputBox"].addElement(self.elements["oOutput"]) self.containers["outputBox"].setPosition("bottomRight") self.containers["buttons"] = Container([0, 0], [5, 5]) self.containers["buttons"].addElement(self.elements["clearButton"]) self.containers["buttons"].addElement(self.elements["quitButton"]) self.containers["buttons"].addElement(self.elements["randomInBut"]) self.containers["buttons"].addElement(self.elements["randomNodesBut"])
def test_get_a_container_from_tree(self): top = Container('top') child = Container('child', top, attribute=0) # Return child from top self.assertEqual(top.get('child'), child)
def test_get_attribute_from_lower_in_tree(self): top = Container('top') child = Container('child', top, attribute=0) # Get attribute of child from top self.assertEqual(top.get_attribute('child'), 0)
def test_no_child_error(self): top = Container('top') child = Container('child', attribute=1) with self.assertRaises(ContainerError): top.add_child('none', child)
def test_get_depth(self): top = Container('top') child = Container('child', top, attribute=0) # Check child is at level 1 self.assertEqual(child.get_depth(), 1)
def test_add_child_not_container(self): top = Container('top') child = Container('child', attribute=1) with self.assertRaises(ContainerError): top.add_child('child', 5)
def TestDeleteContainerDoesNotExist(self): """ Test that we can't delete a container that doesn't exist. """ rc, msg = self.testInsertContainerSmoke() self.assertTrue(rc) c = Container("101010") rc, deleteContainer = self.dao.deleteContainer(c) self.assertTrue(rc) """ QR Code already deleted. """ rc, deleteContainer = self.dao.deleteContainer(c) self.assertFalse(rc) c = Container("101010") """ QR code never in database. """ rc, deleteContainer = self.dao.deleteContainer(c) self.assertFalse(rc) c = None """ Container is NULL """ rc, deleteContainer = self.dao.deleteContainer(c) self.assertFalse(rc)
def __init__(self, obj, styler_obj=None): from_another_styleframe = False if styler_obj: if not isinstance(styler_obj, Styler): raise TypeError('styler_obj must be {}, got {} instead.'.format(Styler.__name__, type(styler_obj).__name__)) styler_obj = styler_obj.create_style() if isinstance(obj, pd.DataFrame): if len(obj) == 0: self.data_df = deepcopy(obj) else: self.data_df = obj.applymap(lambda x: Container(x, styler_obj) if not isinstance(x, Container) else x) elif isinstance(obj, pd.Series): self.data_df = obj.apply(lambda x: Container(x, styler_obj) if not isinstance(x, Container) else x) elif isinstance(obj, (dict, list)): self.data_df = pd.DataFrame(obj).applymap(lambda x: Container(x, styler_obj) if not isinstance(x, Container) else x) elif isinstance(obj, StyleFrame): self.data_df = deepcopy(obj.data_df) from_another_styleframe = True else: raise TypeError("{} __init__ doesn't support {}".format(type(self).__name__, type(obj).__name__)) self.data_df.columns = [Container(col, styler_obj) if not isinstance(col, Container) else deepcopy(col) for col in self.data_df.columns] self.data_df.index = [Container(index, styler_obj) if not isinstance(index, Container) else deepcopy(index) for index in self.data_df.index] self._columns_width = obj._columns_width if from_another_styleframe else {} self._rows_height = obj._rows_height if from_another_styleframe else {} self._custom_headers_style = obj._custom_headers_style if from_another_styleframe else False
def test_container_equality(self): dna1 = get_a_dna_with_some_structure() dna2 = get_a_dna_with_some_structure() self.assertNotEqual(dna1, dna2) container1 = Container(dna1, 5) container2 = Container(dna2, 5) self.assertEquals(container1, container2) self.assertEquals(container1.__hash__(), container2.__hash__())
def test_container_inequality(self): dna1 = DNA([ScoreCard(1, 10), ScoreCard(2, 20)]) dna2 = DNA([ScoreCard(3, 30), ScoreCard(4, 40)]) self.assertNotEqual(dna1, dna2) container1 = Container(dna1, 1) container2 = Container(dna2, 1) self.assertNotEqual(container1, container2) self.assertNotEqual(container1.__hash__(), container2.__hash__())
def test_append_attribute_lower_in_tree(self): top = Container('top') child = Container('child', top, attribute=[0]) top.append_attribute('child', 1) # Get attribute of child from top self.assertEqual(top.get_attribute('child'), [0, 1])
def test_add_children_list_not_container(self): top = Container('top') child = Container('child', attribute=1) children = [child, 5] with self.assertRaises(ContainerError): top.add_children(children)
def attempt_swallow(): window_ids_in_woof = [ win.get_window_id() for win in tree_manager.get_all_windows() ] non_reg_window_ids = [ win for win in system_calls.get_all_system_window_ids() if win not in window_ids_in_woof ] windows = [{ 'window_id': wid, 'window_class': system_calls.get_window_class(wid), 'window_title': system_calls.get_window_title(wid) } for wid in non_reg_window_ids] empty_containers = tree_manager.get_empty_containers() # Attempt to match on title first for ec in empty_containers: if ec.get_window_title() is None: continue title_matches = [ win for win in windows if ec.get_window_title() in win.get('window_title') ] if len(title_matches) > 0: chosen_window = title_matches[0] new_woof_id = tree_manager.get_new_woof_id() new_window = Container(window_id=chosen_window.get('window_id'), woof_id=new_woof_id) ec.swallow(new_window) new_window.redraw() windows.remove(chosen_window) empty_containers = tree_manager.get_empty_containers() # Attempt to match on class for ec in empty_containers: class_matches = [ win for win in windows if ec.get_window_class() == win.get('window_class') ] if len(class_matches) > 0: chosen_window = class_matches[0] new_woof_id = tree_manager.get_new_woof_id() new_window = Container(window_id=chosen_window.get('window_id'), woof_id=new_woof_id) ec.swallow(new_window) new_window.redraw() windows.remove(chosen_window)
def test_add_child_lower_in_tree(self): top = Container('top') child = Container('child', top, attribute=[0]) child2 = Container('child2', attribute=1) top.add_child('child', child2) self.assertEqual(child2.get_depth(), 2) self.assertEqual(child2.parent, child)
def next_fit(weights, num_comparisons=0): containers = [Container()] current_container = containers[0] for w in weights: num_comparisons += 1 if not current_container.put(w): current_container = Container() current_container.put(w) containers.append(current_container) return len(containers), num_comparisons
def test_container_for_crossover(self): DNA.mutate_percentage = 50 dna_1 = get_a_dna_with_some_structure() dna_2 = get_a_dna_with_some_structure() random.shuffle(dna_2.structure) self.assertNotEqual(dna_1, dna_2) container_1 = Container(dna=dna_1, number_of_buckets=5) container_2 = Container(dna=dna_2, number_of_buckets=5) child_container_1, child_container_2 = container_1.crossover( container_2) self.assertFalse(container_1.__eq__(child_container_1)) self.assertFalse(container_2.__eq__(child_container_2)) self.assertFalse(child_container_1.__eq__(child_container_2))
def promptAndGetContainer(self): while True: capacity = UserInput().getFloatInput( "Container's actual capacity (cuft): ", 0, sys.float_info.max) ratedPressure = UserInput().getFloatInput( "Container's rated pressure (psi): ", 0, sys.float_info.max) currentPressure = UserInput().getFloatInput( "Container's current pressure (psi): ", 0, sys.float_info.max) fo2 = UserInput().getFloatInput( "Percentage of oxygen in the container (21% = 0.21): ", 0, 1) print() # Convert capacity in cuft to cuin cubicFtToCubicInConversionRatio = 1728 capacity = capacity * cubicFtToCubicInConversionRatio container = Container(capacity, ratedPressure, currentPressure, fo2) print(container) if input( "Is the above information accurate and would you like to use this container? [y/N]: " ) == 'y': print("Gas will be used.\n") return container else: print("Gas will be used.\n")
def create_container(self, container_name, error_on_existing=False): """ Given a container name, returns a L{Container} item, creating a new Container if one does not already exist. >>> connection.create_container('new_container') <cloudfiles.container.Container object at 0xb77d628c> @param container_name: name of the container to create @type container_name: str @param error_on_existing: raise ContainerExists if container already exists @type error_on_existing: bool @rtype: L{Container} @return: an object representing the newly created container """ self._check_container_name(container_name) response = self.make_request('PUT', [container_name]) buff = response.read() if (response.status < 200) or (response.status > 299): raise ResponseError(response.status, response.reason) if error_on_existing and (response.status == 202): raise ContainerExists(container_name) return Container(self, container_name)
def __init__(self, id, data, item_factory, *args, **kwargs): super().__init__(id, data, item_factory) self.inventories = {} for state in self.states: inventory = item_factory.create_dictionary_from_nouns( data["inventory"][state]) self.inventories[state] = Container(inventory)
def test_create_invalid_data(self): """ Test Container creation with invalid data """ with pytest.raises(ValueError, message='template should fail to instantiate if data dict is missing the flist'): container = Container(name='container') container.validate()
def process(self): while True: next_playing_file = self.get_file_path() print(next_playing_file) if next_playing_file is None: return self.playing = True self.playing_file = next_playing_file GPIO.output(self.config.led_pins.playing, True) container = Container(self.playing_file) self.reader_process = Popen([ filepath(self.config.directory.reader), str(container.resolution) ], stdin=PIPE) self.reader_process.communicate(container.dump) self.reader_process.wait() self.reader_process = None self.playing = False self.playing_file = None GPIO.output(self.config.led_pins.playing, False) if self.required_stop: break else: self.seek_next_file() print('end of process thread')
def stopContainers(c): for ip in genIPlist(c.cntCommon): container = Container(ip, "", c) container.kill() #container.terminate() container.umount() printInfo("***")
def __init__(self, param): geom = param['geometry'] delta = param['mesh_width'] albedo = param['albedo'] container = Container(geom, delta, albedo) self.controller = ContainerController(container)
def rename(self, columns=None, inplace=False): """Renames the underlying dataframe's columns :param dict columns: a dictionary, old_col_name -> new_col_name :param inplace: whether to rename the columns inplace or return a new StyleFrame object :return: self if inplace=True, new StyleFrame object if inplace=False """ if not isinstance(columns, dict): raise TypeError("'columns' must be a dictionary") sf = self if inplace else StyleFrame(self) new_columns = [ col if col not in columns else Container(columns[col], col.style) for col in sf.data_df.columns ] sf._known_attrs['columns'] = sf.data_df.columns = new_columns sf._columns_width.update({ new_col_name: sf._columns_width.pop(old_col_name) for old_col_name, new_col_name in columns.items() if old_col_name in sf._columns_width }) return sf
def main(): pygame.init() screen = pygame.display.set_mode((board_x, board_y)) running = True container = Container(size_x, size_y) while running: blit_container(container, screen) for event in pygame.event.get(): if event and event.type == pygame.KEYDOWN: if event.key == pygame.K_UP: container.rotate_block() elif event.key == pygame.K_DOWN: container.move_block(Direction.DOWN) elif event.key == pygame.K_RIGHT: container.move_block(Direction.RIGHT) elif event.key == pygame.K_LEFT: container.move_block(Direction.LEFT) blit_container(container, screen) time.sleep(0.1) container.move_block(Direction.DOWN) blit_container(container, screen) time.sleep(0.1) container.check_if_layer_filled() time.sleep(0.1) blit_container(container, screen) if container.check_if_ceiling(): end_game(screen, 0)
def tearDown(self): """ Delete the temporary database """ c = Container("101010") # c is container object self.dao.deleteContainer(c) del self.dao
def test_uninstall_container_before_install(self): """ Test uninstall a container without installing """ with pytest.raises(StateCheckError, message='Uninstall container before install should raise an error'): container = Container('container', data=self.valid_data) container.uninstall()
def __init__(self): QMainWindow.__init__(self) # Loading and setting up style sheet self.setupUi(self) style = open('light.css', 'r') style = style.read() self.setStyleSheet(style) # Initializing attributes self.zoomcount = 0 # Creating instances of classes for the main app self.Container = Container(self.textBrowser) self.comp = componentSelector(self) # Setting up interactive canvas self.scene = QGraphicsScene() self.scene.setItemIndexMethod(QGraphicsScene.BspTreeIndex) self.graphicsView.setScene(self.scene) self.graphicsView.setMouseTracking(True) self.graphicsView.keyPressEvent = self.deleteCall self.setDockNestingEnabled(True) self.setCorner(Qt.BottomRightCorner, Qt.RightDockWidgetArea) self.setCorner(Qt.BottomLeftCorner, Qt.LeftDockWidgetArea) self.addDockWidget(Qt.BottomDockWidgetArea, self.dockWidget_2) # Setting up undo stack # self.undoStack = QUndoStack(self) # Calling initialisation functions self.buttonHandler() self.menuBar() self.comp.show()
def test_container_controller(self): xs = CrossSection() xs.set([[1.58, 0.02, 0.0, 1.0], [0.271, 0.0930, 0.168, 0.0]]) xs.set_smat([[0.0, 0.0178], [0.0, 0.0]]) xs.calc_sigr() delta = 1.0 albedo = -1.0 geom = [{'xs': xs, 'width': 100}] container = Container(geom, delta, albedo) #cont.debug() controller = ContainerController(container) count, flag = controller.calc() print("outer iterations: ", count) keff = controller.get_keff() b2 = (math.pi / geom[0]['width'])**2 kana_nume = (xs.sigr(1) + xs.dif(1) * b2) * xs.nusigf(0) + xs.sigs( 0, 1) * xs.nusigf(1) kana_deno = (xs.dif(0) * b2 + xs.sigr(0)) * (xs.dif(1) * b2 + xs.sigr(1)) kana = kana_nume / kana_deno print("kana=", kana) self.assertAlmostEqual(keff, kana, places=4)