~ubuntu-branches/ubuntu/natty/moin/natty-updates

« back to all changes in this revision

Viewing changes to MoinMoin/util/_tests/test_filesys.py

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2008-06-22 21:17:13 UTC
  • mfrom: (0.9.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080622211713-fpo2zrq3s5dfecxg
Tags: 1.7.0-3
Simplify /etc/moin/wikilist format: "USER URL" (drop unneeded middle
CONFIG_DIR that was wrongly advertised as DATA_DIR).  Make
moin-mass-migrate handle both formats and warn about deprecation of
the old one.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
"""
 
3
    MoinMoin - MoinMoin.util.filesys Tests
 
4
 
 
5
    @copyright: 2008 MoinMoin:ThomasWaldmann
 
6
    @license: GNU GPL, see COPYING for details.
 
7
"""
 
8
import sys, os, time
 
9
import shutil, tempfile
 
10
 
 
11
import py.test
 
12
 
 
13
from MoinMoin.util import filesys
 
14
 
 
15
class TestFuid:
 
16
    """ test filesys.fuid (a better mtime() alternative for up-to-date checking) """
 
17
 
 
18
    def setup_method(self, method):
 
19
        self.test_dir = tempfile.mkdtemp('', 'fuid_')
 
20
        self.fname = os.path.join(self.test_dir, "fuid-test")
 
21
        self.tmpname = os.path.join(self.test_dir, "fuid-temp")
 
22
 
 
23
    def teardown_method(self, method):
 
24
        shutil.rmtree(self.test_dir)
 
25
 
 
26
    def testNoFile(self):
 
27
        # no file created
 
28
        uid = filesys.fuid(self.fname)
 
29
 
 
30
        assert uid is None  # there is no file yet, fuid will fail internally and return None
 
31
 
 
32
    def makefile(self, fname, content):
 
33
        f = open(fname, "w")
 
34
        f.write(content)
 
35
        f.close()
 
36
 
 
37
    def testNewFile(self):
 
38
        # freshly created file
 
39
        self.makefile(self.fname, "foo")
 
40
        uid1 = filesys.fuid(self.fname)
 
41
 
 
42
        assert uid1 is not None  # None would mean some failure in fuid()
 
43
 
 
44
    def testUpdateFileInPlace(self):
 
45
        # update file in place, changing size and maybe mtime
 
46
        self.makefile(self.fname, "foo")
 
47
        uid1 = filesys.fuid(self.fname)
 
48
 
 
49
        self.makefile(self.fname, "foofoo")
 
50
        uid2 = filesys.fuid(self.fname)
 
51
 
 
52
        assert uid2 != uid1 # we changed size and maybe mtime
 
53
 
 
54
    def testUpdateFileMovingFromTemp(self):
 
55
        # update file by moving another file over it (see caching.update)
 
56
        # changing inode, maybe mtime, but not size
 
57
        if sys.platform == 'win32':
 
58
            py.test.skip("Inode change detection not supported on win32")
 
59
 
 
60
        self.makefile(self.fname, "foo")
 
61
        uid1 = filesys.fuid(self.fname)
 
62
 
 
63
        self.makefile(self.tmpname, "bar")
 
64
        os.rename(self.tmpname, self.fname)
 
65
        uid2 = filesys.fuid(self.fname)
 
66
 
 
67
        assert uid2 != uid1 # we didn't change size, but inode and maybe mtime
 
68
 
 
69
    def testStale(self):
 
70
        # is a file with mtime older than max_staleness considered stale?
 
71
        if sys.platform != 'win32':
 
72
            py.test.skip("max_staleness check only done on win32 because it doesn't support inode change detection")
 
73
 
 
74
        self.makefile(self.fname, "foo")
 
75
        uid1 = filesys.fuid(self.fname)
 
76
 
 
77
        time.sleep(2) # thanks for waiting :)
 
78
        uid2 = filesys.fuid(self.fname, max_staleness=1)
 
79
        assert uid2 != uid1  # should be considered stale if platform has no inode support
 
80
 
 
81
 
 
82
coverage_modules = ['MoinMoin.util.filesys']