def test_part_one(self): "Test part one example of Packages object" # 1. Create Packages object from text myobj = packages.Packages(text=aoc_24.from_text(PART_ONE_TEXT)) # 2. Check the part one result self.assertEqual(myobj.part_one(verbose=False), PART_ONE_RESULT)
def test_part_two(self): "Test part two example of Packages object" # 1. Create Packages object from text myobj = packages.Packages(part2=True, text=aoc_24.from_text(PART_TWO_TEXT)) # 2. Check the part two result self.assertEqual(myobj.part_two(verbose=False), PART_TWO_RESULT)
def part_two(args, input_lines): "Process part two of the puzzle" # 1. Create the puzzle solver solver = packages.Packages(part2=True, text=input_lines) # 2. Determine the solution for part two solution = solver.part_two(verbose=args.verbose, limit=args.limit) # pylint: disable=assignment-from-none if solution is None: print("There is no solution") else: print("The solution for part two is %s" % (solution)) # 3. Return result return solution is not None
def test_empty_init(self): "Test the default Packages creation" # 1. Create default Packages object myobj = packages.Packages() # 2. Make sure it has the default values self.assertEqual(myobj.part2, False) self.assertEqual(myobj.text, None) self.assertEqual(len(myobj.weights), 0) self.assertEqual(myobj.compartments, 3) self.assertEqual(myobj.balance, 0) # 3. Test methods self.assertEqual(myobj.quantum_entanglement([7, 5, 4, 3, 1]), 420)
def test_text_init(self): "Test the Packages object creation from text" # 1. Create Packages object from text myobj = packages.Packages(text=aoc_24.from_text(EXAMPLE_TEXT)) # 2. Make sure it has the expected values self.assertEqual(myobj.part2, False) self.assertEqual(len(myobj.text), 10) self.assertEqual(len(myobj.weights), 10) self.assertEqual(myobj.compartments, 3) self.assertEqual(myobj.balance, 20) # 3. Test methods self.assertEqual(myobj.min_max_helper(myobj.weights, myobj.balance), 6) myobj.weights.reverse() self.assertEqual(myobj.min_max_helper(myobj.weights, myobj.balance), 2) self.assertEqual( myobj.find_min_max_packages(myobj.weights, myobj.balance), (2, 6)) self.assertEqual( len(myobj.get_weighted(myobj.weights, myobj.balance, 2)), 1) self.assertEqual( len(myobj.get_weighted(myobj.weights, myobj.balance, 3)), 9) self.assertEqual( len(myobj.get_weighted(myobj.weights, myobj.balance, 4)), 11) self.assertEqual( len(myobj.get_weighted(myobj.weights, myobj.balance, 5)), 4) self.assertEqual( myobj.is_remainder_balanced(myobj.weights, [9, 11], myobj.balance, 2), True) self.assertEqual( myobj.is_remainder_balanced(myobj.weights, [1, 8, 11], myobj.balance, 2), True) self.assertEqual( myobj.is_remainder_balanced(myobj.weights, [1, 9, 10], myobj.balance, 2), True) self.assertEqual(myobj.find_best_legroom(), 99)
def run(self): self.ksHandler = makeVersion() if self.file: self.parser = KickstartParser(self.ksHandler) msg = None try: self.parser.readKickstart(self.file) except (KickstartParseError, KickstartValueError) as e: msg = _("The following error was found while parsing your " "kickstart configuration:\n\n%s" % e) except KickstartError: msg = _( "The kickstart file %s could not be opened.") % self.file if msg: dlg = gtk.MessageDialog(None, 0, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, msg) dlg.set_title(_("Error Parsing Kickstart Config")) dlg.set_position(gtk.WIN_POS_CENTER_ON_PARENT) dlg.set_modal(True) dlg.run() dlg.destroy() sys.exit(0) self.xml = xml name_tag = (_("Kickstart")) comment_tag = (_("Create a kickstart file")) self.toplevel = xml.get_widget("main_window") self.toplevel.connect("destroy", self.destroy) self.toplevel.set_icon(iconPixbuf) #bring in widgets from glade file self.options_notebook = xml.get_widget("options_notebook") self.install_radiobutton = xml.get_widget("install_radiobutton") self.category_clist = xml.get_widget("category_clist") self.open_menu = xml.get_widget("open_menu") self.preview_menu = xml.get_widget("preview_menu") self.save_menu = xml.get_widget("save_menu") self.quit_menu = xml.get_widget("quit_menu") self.about_menu = xml.get_widget("about_menu") #populate category list self.category_view = xml.get_widget("list_view") self.category_store = gtk.ListStore(gobject.TYPE_STRING) self.category_view.set_model(self.category_store) col = gtk.TreeViewColumn(_("Subsection"), gtk.CellRendererText(), text=0) col.set_sort_column_id(0) self.category_view.append_column(col) self.category_list = [(_("Basic Configuration")), (_("Installation Method")), (_("Boot Loader Options")), (_("Partition Information")), (_("Network Configuration")), (_("Authentication")), (_("Firewall Configuration")), (_("Display Configuration")), (_("Package Selection")), (_("Pre-Installation Script")), (_("Post-Installation Script"))] for item in self.category_list: iter = self.category_store.append() self.category_store.set_value(iter, 0, item) #bring in basic functions self.basic_class = basic.basic(self, xml, self.options_notebook, self.ksHandler) # Now that we've loaded the UI elements for the first active thing in the notebook, # draw it so we can display a progress bar when yum starts doing stuff. self.toplevel.show() while gtk.events_pending(): gtk.main_iteration() self.bootloader_class = bootloader.bootloader(xml, self.options_notebook, self.ksHandler) self.install_class = install.install(self, xml, self.category_store, self.category_view, self.options_notebook, self.ksHandler) self.partition_class = partition.partition(xml, self.ksHandler) self.network_class = network.network(xml, self.ksHandler) self.auth_class = auth.auth(xml, self.ksHandler) self.firewall_class = firewall.Firewall(xml, self.ksHandler) self.X_class = xconfig.xconfig(xml, self.ksHandler) self.progress_window = progressWindow.ProgressWindow(self.toplevel) self.packages_class = packages.Packages(xml, self.ksHandler, self.progress_window) self.scripts_class = scripts.scripts(xml, self.ksHandler) self.open_menu.connect("activate", self.on_activate_open) self.preview_menu.connect("activate", self.on_activate_preview_options) self.save_menu.connect("activate", self.on_activate_save_options) self.quit_menu.connect("activate", gtk.main_quit) self.about_menu.connect("activate", self.on_about_activate) self.category_view.connect("cursor_changed", self.on_list_view_row_activated) self.options_notebook.connect("switch-page", self.on_notebook_changed) #show gui self.applyKickstart() self.toplevel.show() gtk.main()