| View previous topic :: View next topic |
| Author |
Message |
jens Administrator
Joined: 12 Oct 2005 Posts: 972 Location: duisburg, germany
|
Posted: Sun 25 May, 2008 12:42 Post subject: something wrong with unittests... |
|
|
If i run all tests with "./django-admin.sh test" some plugin_main_menu tests failed. If i only run the test with "./django-admin.sh test plugin_main_menu" it doesn't failed.
Any idea? _________________
http://www.jensdiemer.de | http://www.htfx.de | http://www.python-forum.de
|
|
| Back to top |
|
 |
rantaaho
Joined: 09 Jan 2008 Posts: 47 Location: Kuopio, Finland
|
Posted: Mon 26 May, 2008 12:20 Post subject: |
|
|
Well, for me it fails in both cases
But that's related to used database backend! With mysql plugin_main_menu fails, with sqlite3 it works! How is that possible?? My guess is that in link_snapshot_test:
| Code: |
for page in Page.objects.all().order_by('id'):
|
does not give pages in constant order across database backends, but that's just a first guess without real debugging.
Last edited by rantaaho on Mon 26 May, 2008 13:00; edited 1 time in total |
|
| Back to top |
|
 |
jens Administrator
Joined: 12 Oct 2005 Posts: 972 Location: duisburg, germany
|
|
| Back to top |
|
 |
rantaaho
Joined: 09 Jan 2008 Posts: 47 Location: Kuopio, Finland
|
Posted: Mon 26 May, 2008 13:39 Post subject: |
|
|
No, it doesn't work. And, my guess was wrong That order does not matter: (link_snapshot_test)
| Code: |
for url, links in self._snapshot_iter():
is_links.append(links)
should_be_links.append(snapshot[url])
|
So is_links and should_be_links are in sync by definition. But, with mysql, debug prints below those lines produce:
| Code: | is_links: [[('/2_DDD/', '2_DDD'), ('/2_DDD/2_1_EEE/', '2_1_EEE'), ('/2_DDD/2_2_EEE/', '2_2_EEE'), ('/1_AAA/', '1_AAA')],...
should_be_links: [[('/1_AAA/', '1_AAA'), ('/2_DDD/', '2_DDD'), ('/2_DDD/2_1_EEE/', '2_1_EEE'), ('/2_DDD/2_2_EEE/', '2_2_EEE')],...
|
Which are the same except ordering...
Thus our unit test is working correctly and it has revealed a real bug somewhere else. And that is in db/page.py: _get_page_data()
| Code: |
page_data = Page.objects.values(
"id", "parent", "name", "title", "shortcut"
).filter(showlinks = True).order_by("position")
|
This query does not specify in which order pages with same position (1_AAA and 2_DDD in our unit test) should occur in response. Fix is almost trivial: .order_by("position","shortcut"). Almost, since I'm not sure if the second argument should be "name". I leave the bugfix commit to you.
Now, it makes sense why test was sometimes working and sometimes not. |
|
| Back to top |
|
 |
jens Administrator
Joined: 12 Oct 2005 Posts: 972 Location: duisburg, germany
|
|
| Back to top |
|
 |
rantaaho
Joined: 09 Jan 2008 Posts: 47 Location: Kuopio, Finland
|
Posted: Mon 26 May, 2008 19:43 Post subject: |
|
|
| Yep, now it works with mysql too. |
|
| Back to top |
|
 |
jens Administrator
Joined: 12 Oct 2005 Posts: 972 Location: duisburg, germany
|
Posted: Wed 28 May, 2008 14:50 Post subject: |
|
|
There is still something wrong
If i run all test, there where a few errors like:
| Code: | Traceback (most recent call last):
File "/home/jens/workspace/PyLucid_trunk/pylucid/tests/test_plugin_api.py", line 46, in setUp
template=self.template
File "/home/jens/workspace/PyLucid_trunk/pylucid/tests/__init__.py", line 545, in create_page
page.save()
File "/home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/models/Page.py", line 377, in save
self._prepare_shortcut()
File "/home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/models/Page.py", line 354, in _prepare_shortcut
self.shortcut = getUniqueShortcut(self.shortcut, exclude_shortcut)
File "/home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/tools/shortcuts.py", line 88, in getUniqueShortcut
return makeUnique(shortcut, existing_shortcuts)
File "/home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/tools/shortcuts.py", line 50, in makeUnique
for char in item_name:
TypeError: 'NoneType' object is not iterable |
But if i run a test standalone these error doesn't appear...
Think one of the test change something for all other tests... _________________
http://www.jensdiemer.de | http://www.htfx.de | http://www.python-forum.de
|
|
| Back to top |
|
 |
rantaaho
Joined: 09 Jan 2008 Posts: 47 Location: Kuopio, Finland
|
Posted: Thu 29 May, 2008 13:20 Post subject: |
|
|
Hmm, works for me.
But I have noticed that sometimes different tests are not independent, even though they should be. I don't know reason for that. |
|
| Back to top |
|
 |
jens Administrator
Joined: 12 Oct 2005 Posts: 972 Location: duisburg, germany
|
Posted: Wed 04 Jun, 2008 09:03 Post subject: |
|
|
I found the error, with running the tests via ./django-admin.sh test --verbosity=2
I find out, that the errors comes after the test "unique_shortcuts".
The unique_shortcuts test changed a system settings:
| Code: | def setUp(self):
""" Ensure that auto_shortcuts is false. """
tests.change_preferences(
plugin_name = "system_settings", auto_shortcuts = False
) |
After this, some test failed later... But normaly the preferences settings should be resetet after the next fixtures would be inserted.
It's a problem with the preferences caching! This cache is a dict on modul level (models.Plugin.preference_cache)
So after the fixture was renew the data in database, the Plugin model returns the cached version from the preference_cache dict and not from the database...
It bad, but ok. I change the unittest and change the preferences back in a tearDown() method...
EDIT: See: http://trac.pylucid.net/changeset/1623 _________________
http://www.jensdiemer.de | http://www.htfx.de | http://www.python-forum.de
|
|
| Back to top |
|
 |
jens Administrator
Joined: 12 Oct 2005 Posts: 972 Location: duisburg, germany
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|