FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

something wrong with unittests...

 
Post new topic   Reply to topic    PyLucid - CMS - Forum Forum Index -> system
View previous topic :: View next topic  
Author Message
jens
Administrator


Joined: 12 Oct 2005
Posts: 972
Location: duisburg, germany

PostPosted: Sun 25 May, 2008 12:42    Post subject: something wrong with unittests... Reply with quote

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
View user's profile Send private message
rantaaho



Joined: 09 Jan 2008
Posts: 47
Location: Kuopio, Finland

PostPosted: Mon 26 May, 2008 12:20    Post subject: Reply with quote

Well, for me it fails in both cases Sad

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
View user's profile Send private message
jens
Administrator


Joined: 12 Oct 2005
Posts: 972
Location: duisburg, germany

PostPosted: Mon 26 May, 2008 12:53    Post subject: Reply with quote

Good tip!

I change the code. Used sorted() instead of .order_by():
http://trac.pylucid.net/changeset/1591

Here both tests runs fine, now. Can you test it, too?
_________________

http://www.jensdiemer.de | http://www.htfx.de | http://www.python-forum.de
Back to top
View user's profile Send private message
rantaaho



Joined: 09 Jan 2008
Posts: 47
Location: Kuopio, Finland

PostPosted: Mon 26 May, 2008 13:39    Post subject: Reply with quote

No, it doesn't work. And, my guess was wrong Sad 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
View user's profile Send private message
jens
Administrator


Joined: 12 Oct 2005
Posts: 972
Location: duisburg, germany

PostPosted: Mon 26 May, 2008 13:48    Post subject: Reply with quote

Hm. With http://trac.pylucid.net/changeset/1592 i changed all order_by to .order_by("position", "name", "id") and remove sorted()...

Can you test it?
_________________

http://www.jensdiemer.de | http://www.htfx.de | http://www.python-forum.de
Back to top
View user's profile Send private message
rantaaho



Joined: 09 Jan 2008
Posts: 47
Location: Kuopio, Finland

PostPosted: Mon 26 May, 2008 19:43    Post subject: Reply with quote

Yep, now it works with mysql too.
Back to top
View user's profile Send private message
jens
Administrator


Joined: 12 Oct 2005
Posts: 972
Location: duisburg, germany

PostPosted: Wed 28 May, 2008 14:50    Post subject: Reply with quote

There is still something wrong Sad

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
View user's profile Send private message
rantaaho



Joined: 09 Jan 2008
Posts: 47
Location: Kuopio, Finland

PostPosted: Thu 29 May, 2008 13:20    Post subject: Reply with quote

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
View user's profile Send private message
jens
Administrator


Joined: 12 Oct 2005
Posts: 972
Location: duisburg, germany

PostPosted: Wed 04 Jun, 2008 09:03    Post subject: Reply with quote

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
View user's profile Send private message
jens
Administrator


Joined: 12 Oct 2005
Posts: 972
Location: duisburg, germany

PostPosted: Wed 04 Jun, 2008 15:06    Post subject: Reply with quote

It's not only the auto_shortcuts preferences... There is a concept error, too, if page name and shortcut is None. Normaly this can't happen, because the page_admin plugin handle this. Now i have update the page model to handle this, too: http://trac.pylucid.net/changeset/1626
_________________

http://www.jensdiemer.de | http://www.htfx.de | http://www.python-forum.de
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    PyLucid - CMS - Forum Forum Index -> system All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
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

<< back to PyLucid CMS Homepage



Powered by phpBB © 2001, 2005 phpBB Group