def test_cart(): """ :return: """ c = cart.Cart("products.csv") assert c.calc_total() == 74.3
def test_product(): c = cart.Cart("product.csv") p = c.get_product(0) assert isinstance(p, cart.Product) assert p.name == "Apples" assert p.price == 2.3 assert p.qty == 5
def __init__(self, env): # Create POM objects: self.homepage = homepage.Homepage(env) # self.faq = faq.Faq(self) # self.contact = contact.Contact(self) self.product = product.Product(env) self.products = products.Products(env) self.cart = cart.Cart(env)
def codesize(): parser = argparse.ArgumentParser( prog="codesize", description="Determines the size of your code.") parser.add_argument("cart", help="The filename of the cart.") args = parser.parse_args() ncart = cart.Cart(args.cart) for i in range(8): if ncart.code.get(i, None): if i == 0: print("Bank %d: %d/65536" % (i, len(ncart.code[i]) + len(ncart.format_metadata()))) else: print("Bank %d: %d/65536" % (i, len(ncart.code[i])))
def test_empty_init(self): """Test default Cart object creation""" # 1. Create default Cart object mycart = cart.Cart() # 2. Make sure it has the default values self.assertEqual(mycart.location, (0, 0)) self.assertEqual(mycart.direction, '^') self.assertEqual(mycart.crossings, 0) self.assertEqual(mycart.crashed, None) self.assertEqual(mycart.space, '|') # 3. Check methods self.assertEqual(str(mycart), 'cart: l=(0, 0) d=^ x=0 c=None s=|')
def add_track(self, location, track): "Set a piece of track at a location" # 0. Preconditions assert track in ALL_PIECES assert location[0] >= 0 assert location[1] >= 0 # 1. Add the track self.tracks[location] = track # 2. Adjust the size as needed if location[0] > self.max_cols: self.max_cols = location[0] if location[1] > self.max_rows: self.max_rows = location[1] # 3. If this is a cart, add it to the carts if track in CART_PIECES: self.carts.append(cart.Cart(location=location, direction=track))
str2 += "Phi: %5.2f " % (state[0] - math.pi) str2 += "dphidt: %5.2f " % state[1] str2 += "x: %5.2f " % state[2] str2 += "dxdt: %5.2f " % state[3] str2 += " force: %5.2f " % force gui.draw_string(screen, str2, (20, 10), col, 16) # copy screen onto the display gui.blit(screen) #### MAIN CODE ######################### # create an inverted pendulum cart = cart.Cart(dt=.01) dt = .1 # set the initial angle cart.setAngle(math.pi + 0.02) frameRate = 10 # slow down to 10 steps per second. screen = gui.init_surface((800, 200), " CART + IP demo") force_scale = 10.0 sizes = [2, 1] net = brain.loadBrain()
import cart import math import guisimple import math #### MAIN CODE ######################### # create a cart + inverted pendulum cart = cart.Cart() # set the initial angle cart.setAngle(math.pi + 0.05) dt = 0.1 # Time step for control gui = guisimple.Gui(10) #frameRate=10 # slow down to 10 steps per second. #screen = gui.init_surface((800,200)," CART +IP demo" ) while not gui.check_for_quit(): # loop until user hits escape force = 0.0 # step the car for a single GUI frame cart.step(force, dt) gui.update(cart)
def main(): print("Welcome to the Online Shopping Center (OSC)") username, password = authentication.enterLoginInfo() #create a sucess boolean that returns true if authentication is sucessful sucess = authentication.checkLoginInfo(username,password) #if sucess is false then exit the program if sucess == False: raise Exception("The credentials entered are not valid. Exiting the program..") print("Login credentials accepted.") print("Restocking and initalizing inventory...") inventoryList = system.initalizeInventory() print("Initalizing cart for user: "******"Enter 1 to display the inventory") print("Enter 2 to add items to the cart") print("Enter 3 to remove items from the cart") print("Enter 4 to display running total") print("Enter 5 to checkout") print("Enter 6 to see past purchase history") print("Enter 7 to quit the program") userChoice=int(input("Please choose an option: ")) #if user wants to q then update quit to 1 if userChoice == 7: print("Exiting the program...") break elif userChoice == 1: print("Category: \t Item: \t Price: Count: ") for i in inventoryList: i.display_inventory() #the way that adding Items and Removing Items will work is by #first doing everything locally, so ONLY in the cart we are going #to modify whenever the user adds or removes something #FINALLY in checkout is when we will go send the cart items to the #inventory function (UPDATE INVENTORY) elif userChoice == 2: userCart = cart.addItemToCart(userCart) total = cart.calculateRunningTotal(userCart, inventoryList) print("The current total of the cart is: $",total) elif userChoice == 3: userCart = cart.removeItemFromCart(userCart) total = cart.calculateRunningTotal(userCart, inventoryList) print("The current total of the cart is: $",total) elif userChoice == 4: total = cart.calculateRunningTotal(userCart, inventoryList) print("The current total of the cart is: $",total) elif userChoice == 5: confirm = system.checkout(total) if confirm == "Y": #update inventory for i in userCart.cartContents: for j in inventoryList: if i.item == j.item: j.update_inventory(i.count) #dispaly updated inventory print("Printing updated inventory...") print("Category: \t Item: \t Price: Count: ") for i in inventoryList: i.display_inventory() #store past purchases system.storePastPurchases(userCart,username) #reset cart userCart.cartContents = [] else: pass elif userChoice == 6: system.viewPastPurchases()
def test_cart(): c = cart.Cart("product.csv") assert c.calc_total() == 74.3
def setUp(self): log_write.info('start for case') self.cart = zy_cart.Cart() time.sleep(1) self.t0 = time.time()
def __init__(self, master, fname): # save the master, and filename self.master = master self.fname = fname self.modified = False # open the audio device self.audio = playstopaudio.audio(AUDIO_LIBRARIES) # create the frames self.frames = [] self.frames.append(Frame(bg='black', width=500, height=500)) self.frames.append(Frame(bg='black', width=500, height=500)) self.frames.append(Frame(bg='black', width=500, height=500)) self.frames.append(Frame(bg='black', width=500, height=500)) self.frames.append(Frame(bg='black', width=500, height=500)) # open and process the config file self.carts = [[], [], [], [], []] try: f = open(self.fname, 'r') self.json = json.load(f) f.close() show_welcome = False except: # file doesn't exist or isn't valid JSON - make it empty self.json = [] show_welcome = True # create the carts for x in xrange(5): for row in xrange(ROWS): for col in xrange(COLS): i = row*COLS + col i_ = str(i) try: j = self.json[x][i_] except: j = None self.carts[x].append(cart.Cart(self, self.audio, j)) self.carts[x][i].grid(in_=self.frames[x], row=row, column=col) # create the buttons self.buttons = [] bfont = BTN_FONT smallbfont = SMALLBTN_FONT # we have to define the lambda functions outside of the loop # because otherwise the "i" is taken from the loop's scope and will # always be set to 4 when the function actually runs select_page_lambda = ( lambda: self.select_page(0), lambda: self.select_page(1), lambda: self.select_page(2), lambda: self.select_page(3), lambda: self.select_page(4), ) for i in xrange(5): try: color = self.json[i]['color'] except: color = BTN_COLOR try: highlight = self.json[i]['highlight'] except: highlight = BTN_HL try: title = self.json[i]['title'] except: title = 'Page '+str(i+1) self.buttons.append(PageButton( text=title, width=1, height=BTN_HEIGHT, borderwidth=BTN_BORDER, takefocus=False, font=bfont, wraplength=BTN_WRAPLENGTH, bg=color, activebackground=color, command=select_page_lambda[i] )) self.buttons[i].setup(master, self) self.buttons[i].color = color self.buttons[i].highlight = highlight self.buttons[i].title = title self.buttons[i].active = False self.reloadbutton = Button( text=REFRESH, width=REFRESH_WIDTH, height=SMALLBTN_HEIGHT, borderwidth=SMALLBTN_BORDER, takefocus=False, font=smallbfont, wraplength=SMALLBTN_WRAPLENGTH, bg=SMALLBTN_COLOR, activebackground=SMALLBTN_HL, command=refresh ) self.buttons.append(self.reloadbutton) self.buttons.append(Button( text=LOGOUT, width=LOGOUT_WIDTH, height=SMALLBTN_HEIGHT, borderwidth=SMALLBTN_BORDER, takefocus=False, font=smallbfont, wraplength=SMALLBTN_WRAPLENGTH, bg=SMALLBTN_COLOR, activebackground=SMALLBTN_HL, command=logout )) # put the GUI together self.frames[0].grid(row=0, column=0, rowspan=6) for i in xrange(5): self.buttons[i].grid(row=i, column=1, columnspan=2, sticky=N+S+E+W) self.buttons[5].grid(row=5, column=1, columnspan=1, sticky=N+S+E+W) self.buttons[6].grid(row=5, column=2, columnspan=1, sticky=N+S+E+W) self.activeframe = self.frames[0] self.activebutton = self.buttons[0] self.activeindex = 0 self.select_page(0) if show_welcome: if ALLOW_EDITING: tkMessageBox.showinfo('Welcome to Cartwall!', 'Welcome to Cartwall!\n\nYou\'re editing a new cartwall - '+\ 'right-click any cart or page button to edit it!') else: tkMessageBox.showerror('Cartwall', 'You\'re trying to open a blank cartwall, but editing is '+\ 'disabled - this isn\'t possible.\n\nTry enabling editing '+\ 'in config.py (ALLOW_EDITING = True), or try a different '+\ 'filename.') sys.exit(0) # start timer self.tick()
from weather_info import weather_info from response import ASK_DRINKS, BAKERY_RECOMMEND, DRINKS_COOL_WEATHER, DRINKS_SUNNY_WEATHER, CHECKOUT # initilize flask app app = Flask(__name__) # MySQL configuration app.config['MYSQL_HOST'] = 'localhost' app.config['MYSQL_USER'] = '******' app.config['MYSQL_PASSWORD'] = '******' app.config['MYSQL_DB'] = 'DunkinDonuts' mysql = MySQL(app) # initilize cart bag = cart.Cart() @app.route('/', methods=['POST', 'GET']) def webhook(): req = request.get_json(silent=True, force=True) try: action = req.get('queryResult').get('action') except AttributeError: return 'JSON Error' # action to adds drinks item in cart if action == 'order.items.drinks': params = req.get('queryResult').get('parameters') try: add_drinks(params=params)