Code review comment for lp:~marmyshev/openlp/bug_1117098

Revision history for this message
Phill (phill-ridout) wrote :

Dmitriy,

http://wiki.openlp.org/Development:Unit_Tests should be of some help.

A good example to follow would be http://bazaar.launchpad.net/~openlp-core/openlp/trunk/view/head:/tests/functional/openlp_plugins/songs/test_foilpresenterimport.py

The encoding_declaration_removal_test method is probably similar to what you want to achieve (if a little more basic)

This is probably a nice easy one to start on. We're going to test the function you modified. (set_transparency )There is not any tests written for this module yet, so you will need to create a new file /tests/functional/openlp_core_ui/test_maindisplay.py

In a #TODO: Make a list of all the classes and methods so that we know what needs doing still

Create a class call it "TestMainDisplay" and sub class from TestCase

Because this function has two paths (one if enabled is true and one if enabled is false) you will need to write two tests.

You might as well write a setUp and tearDown functions as these will be helpful when more tests are added. In the setUp you will need to patch and mock __init__ .setAutoFillBackground, .setStyleSheet, .setAttribute, .repaint

Create two test functions, I'd call it "test_set_transparency_enable" & "test_set_transparency_disable"

First thing you will need to do in each test function is write you #GIVEN so something like:
"#GIVEN: Reset mocks: MainDisplay.__init__, MainDisplay.setAutoFillBackground, etc. And an instance of MainDisplay
Now reset the mocks that we are going to check the calls on later and create an instance of MainDisplay

Now you need to write you #WHEN: so one will be like:
"#WHEN: MainDispaly.set_transparency is called with a true value"
So call result = instance.set_transparency(True)

Now write you #THEN:
"#THEN: MainDisplay.setAutoFillBackground, MainDisplay.setStyleSheet, MainDisplay.setAttribute, MainDisplay.repaint should have been called with known values"
Now you will need to assert that your mocks have been called with the expected values so the mock for MainDisplay.setStyleSheet should be called with "QGraphicsView {background: transparent; border: 0px;}"

Hope this gives you a start.

« Back to merge proposal