Ticket #1258: add-test-import-in-repl.darcs.patch

File add-test-import-in-repl.darcs.patch, 11.8 KB (added by davidsarah, at 2011-01-01T20:21:13Z)

test_runner: add test_import_in_repl, which uses 'bin/tahoe debug repl' to import the allmydata module and checks that it comes from the right path. Also, fix a latent bug that caused test_the_right_code to incorrectly conclude that a path mismatch was due to a Unicode path (causing a skip rather than a failure). This version of the patch avoids a confusing shadowing of 'srcfile'. refs #1258

Line 
11 patch for repository davidsarah@dev.allmydata.org:/home/darcs/tahoe/trunk:
2
3Sat Jan  1 19:25:59 GMT Standard Time 2011  david-sarah@jacaranda.org
4  * test_runner: add test_import_in_repl, which uses 'bin/tahoe debug repl' to import the allmydata module and checks that it comes from the right path. Also, fix a latent bug that caused test_the_right_code to incorrectly conclude that a path mismatch was due to a Unicode path (causing a skip rather than a failure). This version of the patch avoids a confusing shadowing of 'srcfile'. refs #1258
5
6New patches:
7
8[test_runner: add test_import_in_repl, which uses 'bin/tahoe debug repl' to import the allmydata module and checks that it comes from the right path. Also, fix a latent bug that caused test_the_right_code to incorrectly conclude that a path mismatch was due to a Unicode path (causing a skip rather than a failure). This version of the patch avoids a confusing shadowing of 'srcfile'. refs #1258
9david-sarah@jacaranda.org**20110101192559
10 Ignore-this: 332920b103412b197b21e05989e3bda0
11] {
12hunk ./src/allmydata/test/test_runner.py 7
13 
14 from twisted.python import usage, runtime
15 from twisted.internet import utils
16-import os.path, re, sys
17+import os.path, re, sys, subprocess
18 from cStringIO import StringIO
19 from allmydata.util import fileutil, pollmixin
20 from allmydata.util.encodingutil import unicode_to_argv, unicode_to_output, get_filesystem_encoding
21hunk ./src/allmydata/test/test_runner.py 18
22 
23 timeout = 240
24 
25-srcfile = allmydata.__file__
26-srcdir = os.path.dirname(os.path.dirname(os.path.normcase(os.path.realpath(srcfile))))
27+def get_root_from_file(src):
28+    srcdir = os.path.dirname(os.path.dirname(os.path.normcase(os.path.realpath(src))))
29+
30+    root = os.path.dirname(srcdir)
31+    if os.path.basename(srcdir) == 'site-packages':
32+        if re.search(r'python.+\..+', os.path.basename(root)):
33+            root = os.path.dirname(root)
34+        root = os.path.dirname(root)
35+    elif os.path.basename(root) == 'src':
36+        root = os.path.dirname(root)
37+
38+    return root
39 
40hunk ./src/allmydata/test/test_runner.py 31
41-rootdir = os.path.dirname(srcdir)
42-if os.path.basename(srcdir) == 'site-packages':
43-    if re.search(r'python.+\..+', os.path.basename(rootdir)):
44-        rootdir = os.path.dirname(rootdir)
45-    rootdir = os.path.dirname(rootdir)
46-elif os.path.basename(rootdir) == 'src':
47-    rootdir = os.path.dirname(rootdir)
48+srcfile = allmydata.__file__
49+rootdir = get_root_from_file(srcfile)
50 
51 bintahoe = os.path.join(rootdir, 'bin', 'tahoe')
52 if sys.platform == "win32":
53hunk ./src/allmydata/test/test_runner.py 58
54 
55 
56 class BinTahoe(common_util.SignalMixin, unittest.TestCase, SkipMixin):
57-    def test_the_right_code(self):
58+    def _check_right_code(self, file_to_check):
59+        root_to_check = get_root_from_file(file_to_check)
60         cwd = os.path.normcase(os.path.realpath("."))
61         root_from_cwd = os.path.dirname(cwd)
62         if os.path.basename(root_from_cwd) == 'src':
63hunk ./src/allmydata/test/test_runner.py 65
64             root_from_cwd = os.path.dirname(root_from_cwd)
65 
66-        same = (root_from_cwd == rootdir)
67+        same = (root_from_cwd == root_to_check)
68         if not same:
69             try:
70hunk ./src/allmydata/test/test_runner.py 68
71-                same = os.path.samefile(root_from_cwd, rootdir)
72+                same = os.path.samefile(root_from_cwd, root_to_check)
73             except AttributeError, e:
74                 e  # hush pyflakes
75 
76hunk ./src/allmydata/test/test_runner.py 76
77             msg = ("We seem to be testing the code at %r,\n"
78                    "(according to the source filename %r),\n"
79                    "but expected to be testing the code at %r.\n"
80-                   % (rootdir, srcfile, root_from_cwd))
81+                   % (root_to_check, file_to_check, root_from_cwd))
82 
83hunk ./src/allmydata/test/test_runner.py 78
84-            root_from_cwdu = os.path.normcase(os.path.normpath(os.getcwdu()))
85+            root_from_cwdu = os.path.dirname(os.path.normcase(os.path.normpath(os.getcwdu())))
86             if os.path.basename(root_from_cwdu) == u'src':
87                 root_from_cwdu = os.path.dirname(root_from_cwdu)
88 
89hunk ./src/allmydata/test/test_runner.py 91
90                 msg += "Please run the tests from the root of the Tahoe-LAFS distribution."
91                 self.fail(msg)
92 
93+    def test_the_right_code(self):
94+        self._check_right_code(srcfile)
95+
96+    def test_import_in_repl(self):
97+        self.skip_if_cannot_run_bintahoe()
98+
99+        p = subprocess.Popen([sys.executable, bintahoe, "debug", "repl"],
100+                             stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
101+        (out, err) = p.communicate("import allmydata; print allmydata.__file__")
102+
103+        self.failUnlessEqual(p.returncode, 0)
104+        first = out.splitlines()[0]
105+        self.failUnless(first.startswith('>>> '))
106+        self._check_right_code(first[4:])
107+
108     def test_path(self):
109         self.skip_if_cannot_run_bintahoe()
110         d = utils.getProcessOutputAndValue(bintahoe, args=["--version-and-path"], env=os.environ)
111hunk ./src/allmydata/test/test_runner.py 137
112                 else:
113                     altverstr = verstr
114 
115+            srcdir = os.path.dirname(os.path.dirname(os.path.normcase(os.path.realpath(srcfile))))
116             required_ver_and_path = "%s: %s (%s)" % (allmydata.__appname__, verstr, srcdir)
117             alt_required_ver_and_path = "%s: %s (%s)" % (allmydata.__appname__, altverstr, srcdir)
118 
119}
120
121Context:
122
123[test_storage.py: fix a pyflakes unused import warning.
124david-sarah@jacaranda.org**20101231220756
125 Ignore-this: df08231540cb7dff9d2b038e47ab30ee
126]
127[test_storage.py: leave at least 512 MiB free when running test_large_share. refs #1195
128david-sarah@jacaranda.org**20101231203215
129 Ignore-this: b2144c0341c3452b5d4ba219e284ea0e
130]
131[storage: use fileutil's version of get_disk_stats() and get_available_space(), use mockery/fakery in tests, enable large share test on platforms with sparse files and if > 4 GiB of disk space is currently available
132zooko@zooko.com**20100910173629
133 Ignore-this: 1304f1164c661de6d5304f993eb9b27b
134]
135[fileutil: copy in the get_disk_stats() and get_available_space() functions from storage/server.py
136zooko@zooko.com**20100910173520
137 Ignore-this: 8b15569715f710f4fc5092f7ca109253
138]
139[Update foolscap version requirement to 0.6.0, to address http://foolscap.lothar.com/trac/ticket/167
140david-sarah@jacaranda.org**20101231060039
141 Ignore-this: 98d2b8086a1a500b9f4565bca5a3810
142]
143[docs/webapi.rst: typos.
144david-sarah@jacaranda.org**20101230034422
145 Ignore-this: d1f5166d72cc711f7e0d9981eac9105e
146]
147[docs/webapi.rst: capitalization, formatting of section on URL character encoding, and a correction about Internet Explorer.
148david-sarah@jacaranda.org**20101230034049
149 Ignore-this: b3b9819d2fb264b4cdc5c8afd4e8c48d
150]
151[docs: corrections and clarifications.
152david-sarah@jacaranda.org**20101227051056
153 Ignore-this: e33202858c7644c58f3f924b164294b6
154]
155[docs: more formatting cleanups and corrections. Spell webapi and wapi as web-API.
156david-sarah@jacaranda.org**20101227050533
157 Ignore-this: 18b23cbfb780df585d8a722a1ec63e94
158]
159[docs/debian.rst: bring description of building dependencies from source up-to-date, and change hostname from allmydata.com to tahoe-lafs.org.
160david-sarah@jacaranda.org**20101212222912
161 Ignore-this: f38462afc88b4475195610385a28391c
162]
163[docs/architecture.rst: correct rst syntax.
164david-sarah@jacaranda.org**20101212202003
165 Ignore-this: 3fbe12feb28bec6f1c63aedbc79aad21
166]
167[docs/architecture.rst: formatting.
168david-sarah@jacaranda.org**20101212201719
169 Ignore-this: 305fa5dfc2939355eaf6d0d2161eb1ff
170]
171[docs: linkification, wording improvements.
172david-sarah@jacaranda.org**20101212201234
173 Ignore-this: 4e67287f527a8bc728cfbd93255d2aae
174]
175[docs: formatting.
176david-sarah@jacaranda.org**20101212201115
177 Ignore-this: 2e0ed394ac7726651d3a4f2c4b0d3798
178]
179[docs/configuration.rst: more formatting tweaks; which -> that.
180david-sarah@jacaranda.org**20101212195522
181 Ignore-this: a7becb7021854ca5a90edd892b36fdd7
182]
183[docs/configuration.rst: more changes to formatting.
184david-sarah@jacaranda.org**20101212194511
185 Ignore-this: 491aac33e5f5268d224359f1447d10be
186]
187[docs/configuration.rst: changes to formatting (mainly putting commands and filenames in monospace).
188david-sarah@jacaranda.org**20101212181828
189 Ignore-this: 8a1480e2d5f43bee678476424615b50f
190]
191[scripts/backupdb.py: more accurate comment about path field.
192david-sarah@jacaranda.org**20101212170320
193 Ignore-this: 50e47a2228a85207bbcd188a78a0d4e6
194]
195[scripts/cli.py: fix missing 'put' in usage example for 'tahoe put'.
196david-sarah@jacaranda.org**20101212170207
197 Ignore-this: 2cbadf066fff611fc03d3c0ff97ce6ec
198]
199[docs/frontends/CLI.rst: changes to formatting (mainly putting commands and filenames in monospace), and to command syntax to reflect that DIRCAP/... is accepted. Clarify the syntax of 'tahoe put' and other minor corrections. Tahoe -> Tahoe-LAFS.
200david-sarah@jacaranda.org**20101212165800
201 Ignore-this: a123ef6b564aa8624d1e79c97068ea12
202]
203[docs/frontends/CLI.rst: Unicode arguments to 'tahoe' work on Windows as of v1.7.1.
204david-sarah@jacaranda.org**20101212063740
205 Ignore-this: 3977a99dfa86ac33a44171deaf43aaab
206]
207[docs/known_issues.rst: fix title and linkify another URL. refs #1225
208david-sarah@jacaranda.org**20101212062817
209 Ignore-this: cc91287f7fb51c23440b3d2fe79c449c
210]
211[docs/known_issues.rst: fix an external link. refs #1225
212david-sarah@jacaranda.org**20101212062435
213 Ignore-this: b8cbf12f353131756c358965c48060ec
214]
215[Fix a link from uri.rst to dirnodes.rst. refs #1225
216david-sarah@jacaranda.org**20101212054502
217 Ignore-this: af6205299f5c9a33229cab259c00f9d5
218]
219[Fix a link from webapi.rst to FTP-and-SFTP.rst. refs #1225
220david-sarah@jacaranda.org**20101212053435
221 Ignore-this: 2b9f88678c3447ea860d6b61e8799858
222]
223[More specific hyperlink to architecture.rst from helper.rst. refs #1225
224david-sarah@jacaranda.org**20101212052607
225 Ignore-this: 50424c768fca481252fabf58424852dc
226]
227[Update hyperlinks between docs, and linkify some external references. refs #1225
228david-sarah@jacaranda.org**20101212051459
229 Ignore-this: cd43a4c3d3de1f832abfa88d5fc4ace1
230]
231[docs/specifications/dirnodes.rst: fix references to mutable.rst. refs #1225
232david-sarah@jacaranda.org**20101212012720
233 Ignore-this: 6819b4b4e06e947ee48b365e840db37d
234]
235[docs/specifications/mutable.rst: correct the magic string for v1 mutable containers. refs #1225
236david-sarah@jacaranda.org**20101212011400
237 Ignore-this: 99a5fcdd40cef83dbb08f323f6cdaaca
238]
239[Move .txt files in docs/frontends and docs/specifications to .rst. refs #1225
240david-sarah@jacaranda.org**20101212010251
241 Ignore-this: 8796d35d928370f7dc6ad2dafdc1c0fe
242]
243[Convert docs/frontends and docs/specifications to reStructuredText format (not including file moves).
244david-sarah@jacaranda.org**20101212004632
245 Ignore-this: e3ceb2d832d73875abe48624ddbb5622
246]
247[scripts/cli.py: remove the disclaimer in the help for 'tahoe cp' that it does not handle non-ASCII filenames well. (At least, we intend to handle them.)
248david-sarah@jacaranda.org**20101130002145
249 Ignore-this: 94c003efaa20b9eb4a83503d79844ca
250]
251[relnotes.txt: fifth -> sixth labor-of-love release
252zooko@zooko.com**20101129045647
253 Ignore-this: 21c245015268b38916e3a138d256c09d
254]
255[Makefile: BB_BRANCH is set to the empty string for trunk, not the string 'trunk'.
256david-sarah@jacaranda.org**20101128233512
257 Ignore-this: 5a7ef8eb10475636d21b91e25b56c369
258]
259[relnotes.txt: eleventh -> twelfth release.
260david-sarah@jacaranda.org**20101128223321
261 Ignore-this: 1e26410156a665271c1170803dea2c0d
262]
263[relnotes.tst: point to known_issues.rst, not known_issues.txt.
264david-sarah@jacaranda.org**20101128222918
265 Ignore-this: 60194eb4544cac446fe4f60b3e34b887
266]
267[quickstart.html: fix link to point to allmydata-tahoe-1.8.1.zip.
268david-sarah@jacaranda.org**20101128221728
269 Ignore-this: 7b3ee86f8256aa12f5d862f689f3ee29
270]
271[TAG allmydata-tahoe-1.8.1
272david-sarah@jacaranda.org**20101128212336
273 Ignore-this: 9c18bdeaef4822f590d2a0d879e00621
274]
275Patch bundle hash:
2760455a63ffa0c8f735e62436ab20107805a1af8f3