Zim

Strange behaviour of tests/stores.py

Asked by Matthieu Rakotojaona

I'm trying to implement a CouchDB store for Zim (see https://bugs.launchpad.net/zim/+bug/505847). I'm using the included tests/stores.py test. I figured I could reuse TestStoresMemory.testManipulate, even though TestFiles doesn't use it.

This test fails, yet it looks normal. Here is the faulty part (irrelevant parts removed):

for oldpath, newpath in (
   (Path('Test:foo'), Path('Test:BAR')),
   (Path('TaskList'), Path('NewPage:Foo:Bar:Baz')),
  ):
   [various tests]
   self.store.move_page(oldpath, newpath)
   [various tests]

   page = self.store.get_page(newpath)
   self.assertTrue(self.store.delete_page(page))
   [various tests]

  # check cleaning up works OK
  page = self.store.get_page(Path('NewPage'))
>>> self.assertFalse(page.haschildren)
  self.assertFalse(page.hascontent)

I have marked the line that breaks. What the test does is simple :
- move 'Tasklist' to 'NewPage:Foo:Bar:Baz' (with all the children)
- test the good execution
- delete the new page name ('NewPage:Foo:Bar:Baz')
- test if 'NewPage' is empty and has no children

The problem is that 'NewPage:Foo' and 'NewPage:Foo:Bar' were created during the 'move' operation (they didn't exist previously). So the test fails, but it's logical. If I replace the last 'get_page()' with 'NewPage:Foo:Bar' or 'NewPage:Foo:Bar:Baz', this part works as expected.

I understand that this test is supposed to work with the MemoryStore, but is this an expected behaviour ?

Question information

Language:
English Edit question
Status:
Solved
For:
Zim Edit question
Assignee:
No assignee Edit question
Solved by:
Jaap Karssenberg
Solved:
Last query:
Last reply:
Revision history for this message
Best Jaap Karssenberg (jaap.karssenberg) said :
#1

On Thu, May 3, 2012 at 9:55 PM, Matthieu Rakotojaona
<email address hidden> wrote:
> I have marked the line that breaks. What the test does is simple :
> - move 'Tasklist' to 'NewPage:Foo:Bar:Baz' (with all the children)
> - test the good execution
> - delete the new page name ('NewPage:Foo:Bar:Baz')
> - test if 'NewPage' is empty and has no children
>
> The problem is that 'NewPage:Foo' and 'NewPage:Foo:Bar' were created during the 'move' operation (they didn't exist previously). So the test fails, but it's logical. If I replace the last 'get_page()' with 'NewPage:Foo:Bar' or 'NewPage:Foo:Bar:Baz', this part works as expected.
>
> I understand that this test is supposed to work with the MemoryStore, but is this an expected behaviour ?

The expected behavior is that all empty parents are cleaned up after a
delete. For the files store this is implemented by the "cleanup"
method in zim.fs that removes the file + any empty parent folders.

Idea is that we do not fill the side pane with unused namespaces.

Hope this help,

Jaap

Revision history for this message
Matthieu Rakotojaona (matthieu-rakotojaona) said :
#2

Thanks Jaap Karssenberg, that solved my question.