[RFC] fake editor for testing edit_commit_message
John Arbash Meinel
john at arbash-meinel.com
Wed Jan 4 23:24:59 GMT 2006
Alexander Belchenko wrote:
> I'm a little working on tests for encoding bugs. This is somewhat
> difficult because often things crash because UnicodeEncodeDecode errors
> raised in mutter or other part of logging subsystem. But another problem
> is to write test for committing with message edited in external editor.
Try pulling my encodings branch from:
http://bzr.arbash-meinel.com/branches/bzr/encoding/
Revno 1496 fixes mutter() so that it won't die from Unicode errors.
>
> I was trying override BZR_EDITOR environment variable with some fake
> editor that simply insert at the begging of file with edited message a
> line like this: "test message from fed".
>
> When I was trying to use python script (see attachment: fed.py) as fake
> editor and set:
>
> set BZR_EDITOR="python fed.py"
>
> I've got WindowsError in subprocess.py when I'm trying to do commit. I
> don't understand why. Fully qualfied path to script also does not help. :-(
I think the problem is that it is trying to spawn a program named
"python fed.py" not a program "python" feeding it the argument "fed.py".
This is definitely a tricky thing to do on windows, since windows
doesn't support having executable scripts (other than .bat files).
I suppose you could do:
echo '@echo off' > test.bat
echo 'python fed.py' >> test.bat
And then use
set BZR_EDITOR='test.bat'
However, if you are doing something like that inside python code itself,
subprocess would look like:
subprocess.Popen(['python', 'fed.py'])
(What you are getting is subprocess.Popen(['python fed.py']))
We also can't just split based on whitespace, especially on windows,
where you have "C:\Program Files\..."
>
> I'm give up and write simple equivalent C-program. See attachment: fed.c
> (and simple SConstruct for building with SCons). This one works fine and
> as expected. So I guess it can be used for testing.
>
> I hope this program written in enough portable way to easily compiling
> on *nix/Cygwin (and probably Mac?).
>
> I have some questions:
>
> 1) Is this `fed` is appropriate for using as part of selftest for
> testing bzrlib/msgeditor.py::edit_commit_message() function?
The problem is now bzr selftest requires that you have a working
compiler, and that we know what it is. (cl, icc, gcc, mingw, etc)
If we can stay with python, it would be greatly prefered. We require
python, and it would be nice to not require other dependencies (yet :).
>
> 2) Where executable binary should be placed? In what directory of
> bzr.dev tree? Probably in bzr.dev/tools subdir?
>
> 3) For building executable binary users must have appropriate compiler
> on their machines. On Windows (and on Cygwin in minimalistic
> installation too) users may have no one compiler installed (even some
> free compiler) on their machines. So I think we should include at least
> windows-exe file in release package for Windows. What you think about?
>
> 4) When running test that defined in class derived from
> TestCaseInTempDir current dir switched to created for test. What the
> simpliest way to obtain location where our helper utility reside?
>
> Alexander
If you must have an executable, you could stash it somewhere under
bzrlib, say 'bzrlib/utils/executable/', and then you can do:
import bzrlib
import os
path = bzrlib.__path__[0]
path = os.path.abspath(os.path.normpath(os.path.join(
path, 'utils', 'executable', 'fed')))
That should give you an exact string which you can tell Windows to look
for. You do need the extra stuff here, because Windows will want you to
use back slashes for executable paths. (That is one of the
incompatibilities with forward slashes, but as long as we know, it is
easy to get right).
I'm guessing in the worst case, it is easiest to just create a batch
file like I mentioned, and use that, rather than compiling C code.
John
=:->
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 256 bytes
Desc: OpenPGP digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20060104/f86f3f98/attachment.pgp
More information about the bazaar
mailing list