Merge lp://staging/~senan/ubuntu-autopilot-tests/DiskUsageAnalyser into lp://staging/ubuntu-autopilot-tests
- DiskUsageAnalyser
- Merge into trunk
Status: | Merged |
---|---|
Merged at revision: | 67 |
Proposed branch: | lp://staging/~senan/ubuntu-autopilot-tests/DiskUsageAnalyser |
Merge into: | lp://staging/ubuntu-autopilot-tests |
Diff against target: |
268 lines (+261/-0) 1 file modified
ubuntu_autopilot_tests/diskusageanalyzer/test_disk_usage_analyzer.py (+261/-0) |
To merge this branch: | bzr merge lp://staging/~senan/ubuntu-autopilot-tests/DiskUsageAnalyser |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Nicholas Skaggs (community) | Approve | ||
Dan Chapman | Pending | ||
Review via email: mp+209323@code.staging.launchpad.net |
This proposal supersedes a proposal from 2014-02-27.
Commit message
Description of the change
Added bug number to the test
Dan Chapman (dpniel) wrote : Posted in a previous version of this proposal | # |
Dan Chapman (dpniel) wrote : Posted in a previous version of this proposal | # |
Senan hey,
So what i was trying to say in IRC is that you are repeating code in a few of your tests. So lets use the test_scan_
lets start with this part of the test
def test_scan_
self.
self.
self.
self.
self.
self.
you use this same process in two tests but selecting a different GtkModelMenuItem for each test, so this can be broken out into its own function and you pass in the name of the GtkModelMenuItem you need for each test
you should use more descriptive names than this, i'm just showing examples
def test_scan_
self.
# .. Rest of test ..
def open_folder_
gear_
self.
#now select the passed in menu item
create_
self.
so now for your tests you can reuse this and just pass in the action_name of the menu item
i.e
self.open_
self.open_
Thats an example of what i mean by breaking up the tests a bit and re-using code makes it easier to maintain.
Regarding my comments on finishing the tests inside the test function, currently on some of the tests you call self.disk_
def Test
1) setup the test (this is the setup function which starts baobab)
2) get the test into the required state for this test. ( so using functions outside the test function )
3) once in the required state for the test, assert what we want to test. as the last part of the test function
take a look at the gedit test as an example the test are only testing one thing only then move on to the next test.
so as an example you could break tests up like
1) test we can open home folder ( but we do not check the folder is being displayed properly thats another test)
2) test that the tree map diplays the home folder
3) test trying to open a folder that doesn't exist.
Each test should not depend on any other test. So create functions of common code that you can use to get a test to its 'required state'
I hope this is of some help
Dan Chapman (dpniel) wrote : Posted in a previous version of this proposal | # |
Senan
so the test_window_title is still failing for me due to the locale issue with the spelling of analyser so i would just remove that and assert 'Disk Usage '.
Also when entering text you need explicitly make sure you get the text entry focus, by either clicking on it assert entry.is_focus = True and then type or you can use the focused_type context manager. e.g currenlty you have this
111 + self.create_
112 + self.pointing_
113 + self.pointing_
114 + self.keyboard.
Which once you have clicked the toggle button we do not actually know if the entry is now visable and has focus before typing. So after the clicking the toggle button you need to
1) assert entry.visible == True
2) either click on the entry and assert entry.is_focus == True before typing
or use the focused_type context manager (which i prefer) which looks something like
entry = self.app.
with self.keyboard.
kb.
self.
kb.
3) test you have ended where you expected :-)
So anywhere in your tests you are entering text you need to do one of the above so we know the entry has focus if we can't get focus then we have a bug :-)
One last thing all boolean values your test that are using ints need to be changed for autopilot 1.4 i.e
self.assertThat
We need to make our tests compliant with 1.4 as soon as possible.
THank you for iterating over these tests, your doing a great job and soon you will get into the swing of it, just hang in there :-)
Dan
Dan Chapman (dpniel) wrote : Posted in a previous version of this proposal | # |
Hey senan, i'm still looking into the problems we were having last night. I am waiting on a reply from someone who may no more so as soon as hear anything we will move onwards with this. Sorry about the delay, sometimes these little niggles need sorting first :-)
Hope you are well
Dan
Prabhendu V Senan (senan) wrote : Posted in a previous version of this proposal | # |
Thanks Dan
On 22 Nov 2013 16:36, "Dan Chapman" <email address hidden> wrote:
> Hey senan, i'm still looking into the problems we were having last night.
> I am waiting on a reply from someone who may no more so as soon as hear
> anything we will move onwards with this. Sorry about the delay, sometimes
> these little niggles need sorting first :-)
>
> Hope you are well
>
> Dan
> --
>
> https:/
> You are the owner of lp:~senan/ubuntu-autopilot-tests/DiskUsageAnalyser.
>
Dan Chapman (dpniel) wrote : Posted in a previous version of this proposal | # |
Senan hey you left too soon, ok ive been having a play and added something ive been working on for a little while (some helpful emulators :-) ), ive adapted your branch slightly here https:/
Hope this helps in the mean time till we can figure out what the difference is between desktop and sandbox
Dan
Prabhendu V Senan (senan) wrote : Posted in a previous version of this proposal | # |
Hi Dan,
I've made some changes to the code in order to address the
filechooserdialog treeview click issue. http://
But I am sure its not the best way to resolve the issue. But I am still not
able to identify the treeview. Looking forward to your review comments.
On Tue, Oct 29, 2013 at 10:01 PM, Prabhendu V Senan <<email address hidden>
> wrote:
> Prabhendu V Senan has proposed merging
> lp:~senan/ubuntu-autopilot-tests/DiskUsageAnalyser into
> lp:ubuntu-autopilot-tests.
>
> Requested reviews:
> Ubuntu Testcase Admins (ubuntu-testcase)
>
> For more details, see:
>
> https:/
> --
>
> https:/
> You are the owner of lp:~senan/ubuntu-autopilot-tests/DiskUsageAnalyser.
>
> === added directory 'ubuntu_
> === added file 'ubuntu_
> === added file
> 'ubuntu_
> --- ubuntu_
> 1970-01-01 00:00:00 +0000
> +++ ubuntu_
> 2013-10-29 16:26:36 +0000
> @@ -0,0 +1,95 @@
> +from autopilot.testcase import AutopilotTestCase
> +from autopilot.matchers import Eventually
> +from testtools.matchers import Equals, Contains, NotEquals
> +
> +from autopilot.input import Mouse, Pointer
> +
> +import os
> +from time import sleep
> +
> +class DiskUsageAnalys
> +
> + def setUp(self):
> + super(DiskUsage
> + self.app = self.launch_
> + self.mainWindow
> + self.pointing_
> +
> + def test_window_
> + # Verify the Disk Usage Analyzer application Title
> +
> self.assertThat
> Analyzer')))
> +
> + def test_scan_
> + self.gear_
> self.app.
> +
> self.pointing_
> + self.pointing_
> + self.create_
> self.app.
> +
> self.pointing_
> + self.pointing_
> + self.assertThat
> self.app.
> + dialog = self.app.
> + self.assertThat
> Folder')))
> + tree_view = dialog.
> + self.pointing_
> +
> + self.create_
> self.app.
> +
> self.po...
Dan Chapman (dpniel) wrote : Posted in a previous version of this proposal | # |
This is really making progress now, nice work. THere is just a couple more things that need tweaking,
1) The test script formatting is a little whacky, it looks like you have been using 8 space tab characters for part of it, ideally you should set this to 4 spaces.
2) When entering /home/ in the file chooser dialog it doesn't seem to close beacause of the autocompletion box being open, you need to make sure after typing either press 'Delete' so the autocompletion box closes or double click the _open button. It would also be good to assert that the PathBar in the dialog is in the /Home directory.
3) With regards to checking the ring and bar charts igf you look in vis their visible property is always set to true even when not visible, so asserting it's visible isn't gaining us anything. We should try and find another way to assert they are visible
If you can make these changes then i think we are nearly there :-) Nice One!
Prabhendu V Senan (senan) wrote : Posted in a previous version of this proposal | # |
> This is really making progress now, nice work. THere is just a couple more
> things that need tweaking,
Thank you very much for the review :)
>
> 1) The test script formatting is a little whacky, it looks like you have been
> using 8 space tab characters for part of it, ideally you should set this to 4
> spaces.
I've fixed the spacing issue
>
> 2) When entering /home/ in the file chooser dialog it doesn't seem to close
> beacause of the autocompletion box being open, you need to make sure after
> typing either press 'Delete' so the autocompletion box closes or double click
> the _open button. It would also be good to assert that the PathBar in the
> dialog is in the /Home directory.
I've already implemented the code for removing auto-completion
editBox = self.app.
#self.
self.
self.
sleep(2)
self.
self.
I am not sure why the auto-completion box is still showing even after this.. can you please check that. Also I didnt understand assert /Home in pathbar.PathBar in filechooserDlg or after clicking _open button
>
> 3) With regards to checking the ring and bar charts igf you look in vis their
> visible property is always set to true even when not visible, so asserting
> it's visible isn't gaining us anything. We should try and find another way to
> assert they are visible
I couldn't find any other propery to validate in this case..:( .. need your help
>
> If you can make these changes then i think we are nearly there :-) Nice One!
Dan Chapman (dpniel) wrote : Posted in a previous version of this proposal | # |
Senan
On 05/02/14 16:41, Prabhendu V Senan wrote:
>>
>>
>> I've already implemented the code for removing auto-completion
>>
>> editBox = self.app.
>> #self.keyboard.
>> self.assertThat
>> self.keyboard.
>> sleep(2)
>> self.keyboard.
>> self.assertThat
>>
>> I am not sure why the auto-completion box is still showing even after this.. can you please check that. Also I didnt understand assert /Home in pathbar.PathBar in filechooserDlg or after clicking _open button
This can be simple resolved by removing the trailing / so '/home/'
becomes '/home'. For the path bar it would be ideal to assert we are in
the required directory either by the pathbars label or stock icon
properties to determin we are in the correct place before clicking open
>> 3) With regards to checking the ring and bar charts igf you look in vis their
>> visible property is always set to true even when not visible, so asserting
>> it's visible isn't gaining us anything. We should try and find another way to
>> assert they are visible
> I couldn't find any other propery to validate in this case..:( .. need your help
I will need to investigate this further as it does seem quite tricky
Corey Goldberg (coreygoldberg) wrote : Posted in a previous version of this proposal | # |
can the sleeps be removed completely?
They tend to make tests brittle, and can generally always be replaced by another waiting mechanism.
check out the AutoPilot Docs... there is a section explaining `wait_for` and `eventually` for replacing `sleep`:
http://
p.s. let me know if you have any questions or need help refactoring... glad to lend a hand.
(cgoldberg on #freenode)
Nicholas Skaggs (nskaggs) wrote : Posted in a previous version of this proposal | # |
Overall, this has come a long way, good work!
I'd run pep8 and pyflakes (or just use flake8 to run them https:/
I notice you have calls like this
self.open_
followed by a check to ensure it becomes visible. It probably makes sense to move this check inside the function as well, so you can be assured the dialog is open. I would do this with all of your utility functions.
Some of your asserts are very hard to understand because they are so long. If they fail, it will be hard to understand why. So for example, instead of
self.assertThat
Let's do
result_header = self.app.
self.assertThat
or if the title isn't changing
result_header = self.app.
self.assertThat
Finally, let's try and add some more comments as to what's going on. Docstrings (http://
All of these will make the code easier to read and understand. Thanks!
Nicholas Skaggs (nskaggs) wrote : Posted in a previous version of this proposal | # |
This looks much better, much easier to read and follow.
Prabhendu V Senan (senan) wrote : Posted in a previous version of this proposal | # |
> This looks much better, much easier to read and follow.
Please let me know If I need to add anything to the test. If everything looks good, then I can start automating Deja-dup :D
Nicholas Skaggs (nskaggs) wrote : Posted in a previous version of this proposal | # |
Just adding some of my comments from IRC :-)
senan, run pep8 and pyflakes on the code and fix any errors.
<elfy> balloons: done
<balloons> senan, I was thinking I would change the name of the non-test functions as well, or move some of the utility functions to the emulator, but I'm reconsidering
<balloons> I think I might be ok with everything on that front
<balloons> senan, I suppose the other thing I would like to see is removing any commented out code, and add some inline coding comments to follow along (docstrings you added are wonderful thank you)
Nicholas Skaggs (nskaggs) wrote : Posted in a previous version of this proposal | # |
I would like to see the bug # added, as discussed on IRC. With that I approve.
Nicholas Skaggs (nskaggs) wrote : | # |
Just an fyi, you don't need to constantly re-create the proposal to merge. It makes it a bit harder to follow actually as the URL changes and I end up looking at old proposals. The merge proposal will update and ping me as you make changes :-)
Nicholas Skaggs (nskaggs) wrote : | # |
I'm still seeing a lot of pep8 errors:
pep8 DiskUsageAnalys
Can these be fixed?
Also, can you rename DiskUsageAnalyser to diskusageanalyser or disk_usage_analyser to follow along with the all lowercase names. It's helpful. I would rename the .py file as well to all lowercase or use _.
Finally, the tests fail on my local machine. I'll attach the log: http://
I would suggest a few other modifications:
DiskUsageAnalys
The asserts like self.assertThat
This is another example where /home should be mocked, and we can mock files and folders as part of it to more thoroughly test things. Have a look at http://
Nicholas Skaggs (nskaggs) wrote : | # |
Looking good! Just get the home patching done and I think we're home free. You should be able to copy/paste the example more or less. That should get the tests passing.
Nicholas Skaggs (nskaggs) wrote : | # |
Any luck with this?
Prabhendu V Senan (senan) wrote : | # |
I didn't get much time to check it :( I tried the link you provided but
still many things going above my head :(
On 10 Mar 2014 23:16, "Nicholas Skaggs" <email address hidden>
wrote:
> Any luck with this?
> --
>
> https:/
> You are the owner of lp:~senan/ubuntu-autopilot-tests/DiskUsageAnalyser.
>
Nicholas Skaggs (nskaggs) wrote : | # |
You need something like this:
def setUp(self):
'''Set-up method'''
super(
#mock out the home dir
self.home_dir = self._patch_home()
....
def _patch_home(self):
#make a temp dir
temp_dir = tempfile.mkdtemp()
logger.
self.
patcher = mock.patch.
patcher.start()
logger.
self.
return temp_dir
Nicholas Skaggs (nskaggs) wrote : | # |
Remember to import mock before trying;
import mock
Prabhendu V Senan (senan) wrote : | # |
I've pushed my latest code. Can you please review it. Is it possible to
maximize a window using autopilot ?. I'm having a issue in launching
filechooser dialog, the open and cancel button are way below my screen and
autopilot fails to click it
On Fri, Mar 14, 2014 at 9:59 PM, Nicholas Skaggs <
<email address hidden>> wrote:
> Remember to import mock before trying;
>
> import mock
> --
>
> https:/
> You are the owner of lp:~senan/ubuntu-autopilot-tests/DiskUsageAnalyser.
>
--
Regards
Senan
http://
- 82. By senan<email address hidden>
-
Added mock to create fake home directory
- 83. By senan<email address hidden>
-
added mock py2 py3 compatibility
- 84. By senan<email address hidden>
-
fixed scan_remote_folder input field issue
- 85. By senan<email address hidden>
-
added comments
- 86. By senan<email address hidden>
-
added comment for gear menu deselection
Nicholas Skaggs (nskaggs) wrote : | # |
Looks good and works on my box. Good first effort, you've come a long way.
First off this is a great start :-) Well Done. Its always the trickiest part learning what you can and can't do with autopilot.
So my first thoughts are (and keeping in mind the near release of autopilot 1.4),
1) the test window title failed on my box. Due to having a different locale where analyzer is actually analyser. So to make this work you would probably be better testing the title with something like Contains('Disk Usage'). Then we miss the strange locale issues.
Note that if you wanted the test to pass on any locale you could assertThat(title, NotEquals(None)) and then assertIsInstanc e(title, unicode). This will test that the title contains text (we don't know what the title text will be, but we can test the title is there and that its unicode.
2) the other 3 tests are very similar so you could probably break them up a little. My first point with this is you are finishing each test outside of the test function with the self.disk_ usage_display_ common( ) call. Ideally you should be finishing each test with asserts as the last lines inside your test function. This way you can see the intended end result of the test i.e "the treeviewmap and ringmap should display a 'x' directory/folder" try and do the setup type parts to get you to the point you need outside the test function and then come back once setup to test the thing you are actually testing
another thing when entering /home in the file chooser dialog you should use the provided function in the keyboard class 'focused_type' so for example once you have clicked the toggle button and the entry is visible you could use something like this
entry = self.app. select_ single( 'GtkFileChooser Entry') focused_ type(entry) as kb: type('/ home') assertThat( entry.text, Equals('/home')) press_and_ release( 'Enter' )
with self.keyboard.
kb.
self.
kb.
This will get the entries focus and type the text see http:// unity.ubuntu. com/autopilot/ api/input. html#autopilot. input.Keyboard. focused_ type
There is also some changes needed to be made for 1.4 if you check this link about boolean properties are now represented correctly and not 1/0. http:// unity.ubuntu. com/autopilot/ porting/ porting. html#gtk- tests-and- boolean- parameters
I'll leave it there for now and see how we fair once these changes are made.
Feel free to ping myself or balloons if your are getting stuck :-)