annotate MoinMoin/_tests/maketestwiki.py @ 2006:1339d6fdc4ff

Changed tests to use py.test. Also changed the semantics a bit - the test wiki directory is only created freshly if it does not exist.
author Alexander Schremmer <alex AT alexanderweb DOT de>
date Fri, 20 Apr 2007 00:12:50 +0200
parents tests/maketestwiki.py@767109c48208
children f5f4dbbd0c51
rev   line source
315
830cf8bdcf24 implemented 'make pagepacks', updated underlay
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
830cf8bdcf24 implemented 'make pagepacks', updated underlay
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
2 """
830cf8bdcf24 implemented 'make pagepacks', updated underlay
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
3 MoinMoin - make a test wiki
830cf8bdcf24 implemented 'make pagepacks', updated underlay
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
4
830cf8bdcf24 implemented 'make pagepacks', updated underlay
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
5 Usage:
830cf8bdcf24 implemented 'make pagepacks', updated underlay
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
6
830cf8bdcf24 implemented 'make pagepacks', updated underlay
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
7 maketestwiki.py
830cf8bdcf24 implemented 'make pagepacks', updated underlay
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
8
830cf8bdcf24 implemented 'make pagepacks', updated underlay
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
9 @copyright: 2005 by Thomas Waldmann
830cf8bdcf24 implemented 'make pagepacks', updated underlay
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
10 @license: GNU GPL, see COPYING for details.
830cf8bdcf24 implemented 'make pagepacks', updated underlay
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
11 """
830cf8bdcf24 implemented 'make pagepacks', updated underlay
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
12
830cf8bdcf24 implemented 'make pagepacks', updated underlay
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
13 import os, sys, shutil, errno, tarfile
830cf8bdcf24 implemented 'make pagepacks', updated underlay
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
14
2006
1339d6fdc4ff Changed tests to use py.test. Also changed the semantics a bit - the test wiki directory is only created freshly if it does not exist.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1603
diff changeset
15 filename = globals().get("__file__") or sys.argv[0]
1339d6fdc4ff Changed tests to use py.test. Also changed the semantics a bit - the test wiki directory is only created freshly if it does not exist.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1603
diff changeset
16 moinpath = os.path.abspath(os.path.join(os.path.dirname(filename), os.pardir, os.pardir))
1339d6fdc4ff Changed tests to use py.test. Also changed the semantics a bit - the test wiki directory is only created freshly if it does not exist.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1603
diff changeset
17 sys.path.insert(0, moinpath)
315
830cf8bdcf24 implemented 'make pagepacks', updated underlay
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
18
2006
1339d6fdc4ff Changed tests to use py.test. Also changed the semantics a bit - the test wiki directory is only created freshly if it does not exist.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1603
diff changeset
19 WIKI = os.path.abspath(os.path.join(moinpath, 'tests', 'wiki'))
1339d6fdc4ff Changed tests to use py.test. Also changed the semantics a bit - the test wiki directory is only created freshly if it does not exist.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1603
diff changeset
20 SHARE = os.path.abspath(os.path.join(moinpath, 'wiki'))
1339d6fdc4ff Changed tests to use py.test. Also changed the semantics a bit - the test wiki directory is only created freshly if it does not exist.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1603
diff changeset
21
315
830cf8bdcf24 implemented 'make pagepacks', updated underlay
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
22
830cf8bdcf24 implemented 'make pagepacks', updated underlay
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
23 def removeTestWiki():
830cf8bdcf24 implemented 'make pagepacks', updated underlay
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
24 print 'removing old wiki ...'
830cf8bdcf24 implemented 'make pagepacks', updated underlay
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
25 for dir in ['data', 'underlay']:
830cf8bdcf24 implemented 'make pagepacks', updated underlay
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
26 try:
830cf8bdcf24 implemented 'make pagepacks', updated underlay
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
27 shutil.rmtree(os.path.join(WIKI, dir))
830cf8bdcf24 implemented 'make pagepacks', updated underlay
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
28 except OSError, err:
348
f308f9478d51 Fixed maketestwiki.py for cases when there is not testwiki dir, or when run on Windows (How i hate this WindowsError exception).
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 315
diff changeset
29 if not (err.errno == errno.ENOENT or
f308f9478d51 Fixed maketestwiki.py for cases when there is not testwiki dir, or when run on Windows (How i hate this WindowsError exception).
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 315
diff changeset
30 (err.errno == 3 and os.name == 'nt')):
315
830cf8bdcf24 implemented 'make pagepacks', updated underlay
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
31 raise
830cf8bdcf24 implemented 'make pagepacks', updated underlay
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
32
2006
1339d6fdc4ff Changed tests to use py.test. Also changed the semantics a bit - the test wiki directory is only created freshly if it does not exist.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1603
diff changeset
33
315
830cf8bdcf24 implemented 'make pagepacks', updated underlay
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
34 def copyData():
830cf8bdcf24 implemented 'make pagepacks', updated underlay
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
35 print 'copying data ...'
830cf8bdcf24 implemented 'make pagepacks', updated underlay
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
36 src = os.path.join(SHARE, 'data')
830cf8bdcf24 implemented 'make pagepacks', updated underlay
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
37 dst = os.path.join(WIKI, 'data')
830cf8bdcf24 implemented 'make pagepacks', updated underlay
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
38 shutil.copytree(src, dst)
830cf8bdcf24 implemented 'make pagepacks', updated underlay
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
39
830cf8bdcf24 implemented 'make pagepacks', updated underlay
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
40
830cf8bdcf24 implemented 'make pagepacks', updated underlay
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
41 def untarUnderlay():
830cf8bdcf24 implemented 'make pagepacks', updated underlay
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
42 print 'untaring underlay ...'
830cf8bdcf24 implemented 'make pagepacks', updated underlay
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
43 tar = tarfile.open(os.path.join(SHARE, 'underlay.tar.bz2'), mode='r:bz2')
830cf8bdcf24 implemented 'make pagepacks', updated underlay
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
44 for member in tar:
830cf8bdcf24 implemented 'make pagepacks', updated underlay
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
45 tar.extract(member, WIKI)
830cf8bdcf24 implemented 'make pagepacks', updated underlay
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
46 tar.close()
830cf8bdcf24 implemented 'make pagepacks', updated underlay
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
47
830cf8bdcf24 implemented 'make pagepacks', updated underlay
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
48
2006
1339d6fdc4ff Changed tests to use py.test. Also changed the semantics a bit - the test wiki directory is only created freshly if it does not exist.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1603
diff changeset
49 def run(skip_if_existing=False):
348
f308f9478d51 Fixed maketestwiki.py for cases when there is not testwiki dir, or when run on Windows (How i hate this WindowsError exception).
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 315
diff changeset
50 try:
f308f9478d51 Fixed maketestwiki.py for cases when there is not testwiki dir, or when run on Windows (How i hate this WindowsError exception).
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 315
diff changeset
51 os.makedirs(WIKI)
f308f9478d51 Fixed maketestwiki.py for cases when there is not testwiki dir, or when run on Windows (How i hate this WindowsError exception).
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 315
diff changeset
52 except OSError, e:
f308f9478d51 Fixed maketestwiki.py for cases when there is not testwiki dir, or when run on Windows (How i hate this WindowsError exception).
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 315
diff changeset
53 if e.errno != errno.EEXIST:
f308f9478d51 Fixed maketestwiki.py for cases when there is not testwiki dir, or when run on Windows (How i hate this WindowsError exception).
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 315
diff changeset
54 raise
f308f9478d51 Fixed maketestwiki.py for cases when there is not testwiki dir, or when run on Windows (How i hate this WindowsError exception).
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 315
diff changeset
55
2006
1339d6fdc4ff Changed tests to use py.test. Also changed the semantics a bit - the test wiki directory is only created freshly if it does not exist.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1603
diff changeset
56 if skip_if_existing and os.path.exists(os.path.join(WIKI, 'data')):
1339d6fdc4ff Changed tests to use py.test. Also changed the semantics a bit - the test wiki directory is only created freshly if it does not exist.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1603
diff changeset
57 return
315
830cf8bdcf24 implemented 'make pagepacks', updated underlay
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
58 removeTestWiki()
830cf8bdcf24 implemented 'make pagepacks', updated underlay
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
59 copyData()
830cf8bdcf24 implemented 'make pagepacks', updated underlay
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
60 untarUnderlay()
830cf8bdcf24 implemented 'make pagepacks', updated underlay
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
61
830cf8bdcf24 implemented 'make pagepacks', updated underlay
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
62 if __name__ == '__main__':
830cf8bdcf24 implemented 'make pagepacks', updated underlay
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
63 run()
830cf8bdcf24 implemented 'make pagepacks', updated underlay
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
64