-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mocks for chefshow and barcode_generator
Add mocks to the unit tests for chefshow and barcode_generator Remove previously added optional arguments to disable costly behaviour of generating barcodes or displaying the window and starting the mainloop. Not needed now they are mocked. Coverage now reports 100%
- Loading branch information
1 parent
92f3461
commit e4106b7
Showing
4 changed files
with
80 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,74 @@ | ||
from chefshow import ChefShow | ||
from slideshow import SlideShow | ||
|
||
|
||
def test_init_callback(): | ||
def test_init_callback(mocker): | ||
"""Test init function sets the SlideShow callback to update_image""" | ||
chefshow = ChefShow(show=False) | ||
mocker.patch("tkinter.Tk") | ||
mocker.patch("tkinter.Button") | ||
chefshow = ChefShow() | ||
|
||
assert chefshow.start_callback == chefshow.update_image | ||
|
||
|
||
def test_init_title(): | ||
def test_init_title(mocker): | ||
"""Test init function sets the SlideShow title""" | ||
chefshow = ChefShow(show=False) | ||
assert chefshow.root.title() == "ChefCodes" | ||
|
||
mocker.patch("tkinter.Tk") | ||
mocker.patch("tkinter.Button") | ||
chefshow = ChefShow() | ||
|
||
def test_init_bcg(): | ||
"""Test init function creates a BarcodeGenerator""" | ||
chefshow = ChefShow(show=False) | ||
assert chefshow.ccg.count > 0 | ||
chefshow.root.title.assert_called_once_with("ChefCodes") | ||
|
||
|
||
def test_init_jump(): | ||
def test_init_jump(mocker): | ||
"""Test init function jumps to user specified index""" | ||
chefshow = ChefShow(100, show=False) | ||
assert chefshow.ccg.index == 100 | ||
assert chefshow.ccg.code == "01C" | ||
mocker.patch("tkinter.Tk") | ||
mocker.patch("tkinter.Button") | ||
mocker.patch("treepoem.generate_barcode") | ||
mocker.patch("chefshow.BarcodeGenerator") | ||
chefshow = ChefShow(100) | ||
|
||
chefshow.ccg.jump.assert_called_once_with(100) | ||
|
||
|
||
def test_update_progress(): | ||
def test_toggle_start_update_progress(mocker): | ||
"""Test toggle_start function updates the progress label""" | ||
chefshow = ChefShow(99, show=False) | ||
code = chefshow.ccg.next(False) | ||
chefshow.update_progress(code) | ||
label_text = chefshow.progress_label.config('text')[4] | ||
assert label_text == "100 (0.04%): 01C" | ||
mocker.patch("tkinter.Tk") | ||
mocker.patch("tkinter.Button") | ||
mocker.patch("treepoem.generate_barcode") | ||
chefshow = ChefShow() | ||
|
||
mocker.patch("PIL.ImageTk.PhotoImage") | ||
mocker.patch.object(chefshow.ccg, "next", return_value="01C") | ||
mocker.patch.object(chefshow, "update_progress") | ||
mocker.patch.object(chefshow.ccg, "barcode") | ||
chefshow.update_image() | ||
|
||
chefshow.update_progress.assert_called_once_with("01C") | ||
|
||
|
||
def test_update_progress(mocker): | ||
"""Test update_progress calls SlideShow's update_progress""" | ||
mocker.patch("tkinter.Tk") | ||
mocker.patch("tkinter.Button") | ||
mocker.patch("treepoem.generate_barcode") | ||
chefshow = ChefShow() | ||
|
||
def test_jump_back(): | ||
m = mocker.patch.object(SlideShow, "update_progress") | ||
chefshow.update_progress("01C") | ||
|
||
m.assert_called_once_with(0, 238328, '01C') | ||
|
||
|
||
def test_jump_back(mocker): | ||
"""Test toggle_start function updates the progress label""" | ||
chefshow = ChefShow(100, show=False) | ||
assert chefshow.ccg.index == 100 | ||
assert chefshow.ccg.code == "01C" | ||
mocker.patch("tkinter.Tk") | ||
mocker.patch("tkinter.Button") | ||
mocker.patch("treepoem.generate_barcode") | ||
chefshow = ChefShow(100) | ||
|
||
mocker.patch.object(SlideShow, "update_progress") | ||
mocker.patch.object(chefshow.ccg, "jump") | ||
chefshow.jump_back() | ||
assert chefshow.ccg.index == 90 | ||
assert chefshow.ccg.code == "01s" | ||
|
||
chefshow.ccg.jump.assert_called_with(90) |