def test_Checkout_total_method(scanned_codes, prices, expected): pos = checkout.Checkout(prices) for item_code in scanned_codes: pos.scan(item_code) total = pos.total() assert total == expected
def test_Checkout_scan_method(): scanned_codes = ["A", "B", "P"] pos = checkout.Checkout({"A": 1, "B": 2, "P": 3}) for item_code in scanned_codes: pos.scan(item_code) assert pos.scanned_codes == scanned_codes # Also test it does not scan items not in the prices dictionary pos.scan("C") assert pos.scanned_codes == scanned_codes
def test_incremental(self): co = checkout.Checkout() co.scan("A") self.assertEqual(50, co.calculate_total()) co.scan("B") self.assertEqual(80, co.calculate_total()) co.scan("A") self.assertEqual(130, co.calculate_total()) co.scan("A") self.assertEqual(160, co.calculate_total()) co.scan("B") self.assertEqual(175, co.calculate_total())
def __init__(self): self._options = {} #Add menu classes self._optionLookup = {} #Add/order your menu option here self._options = [ addSubproject.AddSubproject(), bundle.Bundle(), bundle.Unbundle(), branches.Branches(), status.Status(), stash.Stash(), checkout.Checkout(), push.Push(), pull.Pull(), commit.Commit(), publish.Publish(), clone.Clone(), config.Config(), grapeConfig.WriteConfig(), foreach.ForEach(), merge.Merge(), mergeDevelop.MergeDevelop(), mergeRemote.MergeRemote(), deleteBranch.DeleteBranch(), newWorkingTree.NewWorkingTree(), resolveConflicts.ResolveConflicts(), review.Review(), test.Test(), updateLocal.UpdateLocal(), updateSubproject.UpdateSubproject(), hooks.InstallHooks(), hooks.RunHook(), updateView.UpdateView(), version.Version(), walkthrough.Walkthrough(), quit.Quit() ] #Add/order the menu sections here self._sections = [ 'Getting Started', 'Code Reviews', 'Workspace', 'Merge', 'Gitflow Tasks', 'Hooks', 'Patches', 'Project Management', 'Other' ]
class Main: inventory_dict = dict() # key: product code value: [name, price] def __init__(self): pass def run_main(self): self.readFile() def readFile(self): line = "" price = 0.00 with open("inventory.txt", "r") as reader: line = reader.readline() while line != '': code, name, price = line.split() price = float(price) self.inventory_dict[code] = [ name, price ] # account for product code/price line = reader.readline() # advance to next line reader.close() new_main = Main() new_checkout = checkout.Checkout() new_main.readFile() new_checkout.PromptUser(new_main.inventory_dict)
def setUp(self): self.co = checkout.Checkout(RULES)
def calc_price(items): co = checkout.Checkout(RULES) for item in items: co.scan(item) return co.total()
def main(options): retval = True # everything was OK co = checkout.Checkout(options.sourcedir) # determine build architectures buildarchs = set() for m in options.machines: buildarchs |= set(m.get_buildarchs()) buildarchs = list(buildarchs) testcases = [] for build in options.builds: debug.log('starting build: %s' % build.name) build.configure(co, buildarchs) for machine in options.machines: for test in options.tests: debug.log('running test %s on %s, cwd is %s' % (test.name, machine.name, os.getcwd())) path = make_results_dir(options, build, machine, test) write_description(options, co, build, machine, test, path) start_timestamp = datetime.datetime.now() try: harness.run_test(build, machine, test, path) except TimeoutError: retval = False msg = 'Timeout while running test' if options.keepgoing: msg += ' (attempting to continue)' debug.error(msg) end_timestamp = datetime.datetime.now() testcases.append(write_errorcase(build, machine, test, path, msg, start_timestamp, end_timestamp) ) if options.keepgoing: continue else: if options.xml: write_xml_report(testcases, path) return retval except Exception: retval = False msg = 'Exception while running test' if options.keepgoing: msg += ' (attempting to continue):' debug.error(msg) end_timestamp = datetime.datetime.now() testcases.append(write_errorcase(build, machine, test, path, msg, start_timestamp, end_timestamp) ) if options.keepgoing: traceback.print_exc() continue else: if options.xml: write_xml_report(testcases, path) raise end_timestamp = datetime.datetime.now() debug.log('test complete, processing results') try: passed = harness.process_results(test, path) debug.log('result: %s' % ("PASS" if passed else "FAIL")) except Exception: retval = False msg = 'Exception while processing results' if options.keepgoing: msg += ' (attempting to continue):' debug.error(msg) if options.keepgoing: traceback.print_exc() else: if options.xml: write_xml_report(testcases, path) raise if not passed: retval = False testcases.append( write_testcase(build, machine, test, path, passed, start_timestamp, end_timestamp)) # produce JUnit style xml report if requested if options.xml: path = make_run_dir(options, build, machine) write_xml_report(testcases, path) debug.log('all done!') return retval
def test_totals(self): co = checkout.Checkout() co.scan("") self.assertEqual(0, co.calculate_total()) co = checkout.Checkout() co.scan("A") self.assertEqual(50, co.calculate_total()) co = checkout.Checkout() co.scan("AB") self.assertEqual(80, co.calculate_total()) co = checkout.Checkout() co.scan("CDBA") self.assertEqual(115, co.calculate_total()) co = checkout.Checkout() co.scan("AA") self.assertEqual(100, co.calculate_total()) co = checkout.Checkout() co.scan("AAA") self.assertEqual(130, co.calculate_total()) co = checkout.Checkout() co.scan("AAAA") self.assertEqual(180, co.calculate_total()) co = checkout.Checkout() co.scan("AAAAA") self.assertEqual(230, co.calculate_total()) co = checkout.Checkout() co.scan("AAAAAA") self.assertEqual(260, co.calculate_total()) co = checkout.Checkout() co.scan("AAAB") self.assertEqual(160, co.calculate_total()) co = checkout.Checkout() co.scan("AAABB") self.assertEqual(175, co.calculate_total()) co = checkout.Checkout() co.scan("AAABBD") self.assertEqual(190, co.calculate_total()) co = checkout.Checkout() co.scan("DABABA") self.assertEqual(190, co.calculate_total())
def co(): return checkout.Checkout(PRICING_CONFIG)
def main(options): retval = True # everything was OK co = checkout.Checkout(options.sourcedir) # determine build architectures buildarchs = set() for m in options.machines: buildarchs |= set(m.get_buildarchs()) buildarchs = list(buildarchs) for build in options.builds: debug.log('starting build: %s' % build.name) build.configure(co, buildarchs) for machine in options.machines: for test in options.tests: debug.log('running test %s on %s, cwd is %s' % (test.name, machine.name, os.getcwd())) path = make_results_dir(options, build, machine, test) write_description(options, co, build, machine, test, path) try: harness.run_test(build, machine, test, path) except TimeoutError: retval = False msg = 'Timeout while running test' if options.keepgoing: msg += ' (attempting to continue)' debug.error(msg) if options.keepgoing: continue else: return retval except Exception: retval = False msg = 'Exception while running test' if options.keepgoing: msg += ' (attempting to continue):' debug.error(msg) if options.keepgoing: traceback.print_exc() continue else: raise debug.log('test complete, processing results') try: passed = harness.process_results(test, path) except Exception: retval = False msg = 'Exception while processing results' if options.keepgoing: msg += ' (attempting to continue):' debug.error(msg) if options.keepgoing: traceback.print_exc() else: raise if not passed: retval = False debug.log('all done!') return retval