On Sat, Jan 12, 2002 at 04:36:27PM -0500, Garrett Rooney wrote:
>...
> > +# General modules
> > +import shutil, string, sys, re, os.path, traceback
> > +
> > +# The `svntest' module
> > +try:
> > + import svntest
> > +except SyntaxError:
> > + sys.stderr.write('[SKIPPED] ')
> > + print "<<< Please make sure you have Python 2 or better! >>>"
> > + traceback.print_exc(None,sys.stdout)
> > + raise SystemExit
> > +
> > +
> > +# Quick macro for auto-generating sandbox names
> > +def sandbox(x):
> > + return "basic_tests-" + `test_list.index(x)`
> > +
> > +# (abbreviation)
> > +path_index = svntest.actions.path_index
path_index isn't used anywhere, so this isn't needed
>...
> > +def stat_unversioned_file_in_current_dir():
> > + "stat an unversioned file in the current directory"
> > +
> > + sbox = sandbox(stat_unversioned_file_in_current_dir)
> > + wc_dir = os.path.join(svntest.main.general_wc_dir, sbox)
> > + if svntest.actions.make_repo_and_wc(sbox): return 1
> > +
> > + was_cwd = os.getcwd()
> > + os.chdir(wc_dir)
> > +
> > + svntest.main.file_append('foo', 'a new file')
> > +
> > + stat_output, err_output = svntest.main.run_svn(None, 'stat', 'foo')
> > +
> > + if len(stat_output) != 1:
> > + os.chdir(was_cwd)
> > + return 1
> > +
> > + if len(err_output) != 0:
> > + os.chdir(was_cwd)
> > + return 1
> > +
> > + os.chdir(was_cwd)
> > + return 0
The easiest thing to do above is:
was_cwd = os.getcwd()
try:
os.chdir(wc_dir)
svntest.main.file_append('foo', 'a new file')
stat_output, ...
if len(stat_output) != 1:
return 1
if len(err_output) != 0:
return 1
return 0
finally:
os.chdir(was_cwd)
In the above code, the "finally" step will *always* execute. Thus, you will
always get back to the original directory whether you exit with success,
failure, or even because of an exception.
(and those two "if" conditions are simple enough to join with "or")
Otherwise, +1 with or without the above changes.
Cheers,
-g
--
Greg Stein, http://www.lyra.org/
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Sat Oct 21 14:36:56 2006