def test_generate_barcode(mocker): """Test generate_barcode function""" mocker.patch("treepoem.generate_barcode") bcg = BarcodeGenerator() assert bcg.barcode is None bcg.generate_barcode() assert treepoem.generate_barcode.called is True
def test_jump_100(mocker): """Test jump function with argument of 100""" mocker.patch("treepoem.generate_barcode") bcg = BarcodeGenerator() assert bcg.index == 0 bcg.jump(100) assert bcg.index == 100 assert bcg.code == "01C"
def test_next(mocker): """Test next function moves index by 1""" mocker.patch("treepoem.generate_barcode") bcg = BarcodeGenerator() assert bcg.index == 0 bcg.next() assert bcg.index == 1 assert bcg.code == "001"
def test_jump_generate_barcode(mocker): """Test jump function will generate a barcode""" mocker.patch("treepoem.generate_barcode") bcg = BarcodeGenerator() assert bcg.index == 0 assert bcg.barcode is None bcg.jump(1) assert bcg.index == 1 assert bcg.code == "001" assert treepoem.generate_barcode.called is True
def __init__(self, start_index=None): super().__init__('ChefCodes', self.update_image) self.ccg = BarcodeGenerator() if start_index: self.ccg.jump(start_index) self.back_button = tk.Button(self.panel, text='Back', command=self.jump_back) self.back_button.pack(side='bottom') # display the main window and enter the main loop self.show()
class ChefShow(SlideShow): """Class to represent the ChefClub barcode slideshow""" def __init__(self, start_index=None): super().__init__('ChefCodes', self.update_image) self.ccg = BarcodeGenerator() if start_index: self.ccg.jump(start_index) self.back_button = tk.Button(self.panel, text='Back', command=self.jump_back) self.back_button.pack(side='bottom') # display the main window and enter the main loop self.show() def update_image(self): """Change the image that is displayed with the next one""" code = self.ccg.next() self.update_progress(code) # treepoem returns a PIL object, we can resize that directly barcode = self.ccg.barcode.resize((100, 100)) # Use PhotoImage so the barcode image data can be understood by tk barcode = ImageTk.PhotoImage(barcode) self.panel.image = barcode # avoid garbage collection self.panel.config(image=barcode) # Delay can not be too low, treepoem will choke running the barcode # generation child processes self.panel.after(1000, self.update_image) def jump_back(self, distance=10): """Jump backwards some number of places in the slideshow""" self.ccg.jump(self.ccg.index - distance) self.update_progress() def update_progress(self, code=''): """Update the progress label with some stats""" super().update_progress(self.ccg.index, self.ccg.count, code)
def test_init(): """Test init function populates its internal list of codes""" bcg = BarcodeGenerator() assert bcg.count > 0