[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: [PATCH] Eliminate temporary variables by using for .. else construct (test suite)

From: Sander Roobol <phy_at_wanadoo.nl>
Date: 2003-09-09 12:47:24 CEST

Filed as issue #1513.

Sander

On Sun, Aug 31, 2003 at 10:00:23PM +0200, e.huelsmann@gmx.net wrote:
>
> Doing the work for the test suite, I rewrote all for loops to use break ..
> else where ever possible.
>
> Log:
> [[[
> Use for .. else construct as often as possible, eliminating the need for
> temporary variables.
>
> * subversion/tests/clients/cmdline/commit_tests.py
> * subversion/tests/clients/cmdline/copy_tests.py
> * subversion/tests/clients/cmdline/diff_tests.py
> * subversion/tests/clients/cmdline/externals_tests.py
> * subversion/tests/clients/cmdline/prop_tests.py
> * subversion/tests/clients/cmdline/stat_tests.py
> * subversion/tests/clients/cmdline/update_tests.py
>
>
> ]]]
>
> Index: subversion/tests/clients/cmdline/commit_tests.py
> ===================================================================
> --- subversion/tests/clients/cmdline/commit_tests.py (revision 6931)
> +++ subversion/tests/clients/cmdline/commit_tests.py (working copy)
> @@ -1854,24 +1856,20 @@
> # out-of-dateness error.
> outlines, errlines = svntest.main.run_svn(1, 'commit', '-m', 'blah',
> omega_path)
> - out_of_date_error = 0
> for line in errlines:
> if re.match(".*out of date.*", line):
> - out_of_date_error = 1;
> -
> - if out_of_date_error == 0:
> + break
> + else:
> return 1
>
> # Attempt to delete directory C. This should return an (expected)
> # out-of-dateness error.
> outlines, errlines = svntest.main.run_svn(1, 'commit', '-m', 'blah',
> C_path)
> - out_of_date_error = 0
> for line in errlines:
> if re.match(".*out of date.*", line):
> - out_of_date_error = 1;
> -
> - if out_of_date_error == 0:
> + break
> + else:
> return 1
>
> return 0
> Index: subversion/tests/clients/cmdline/copy_tests.py
> ===================================================================
> --- subversion/tests/clients/cmdline/copy_tests.py (revision 6931)
> +++ subversion/tests/clients/cmdline/copy_tests.py (working copy)
> @@ -497,9 +497,10 @@
> mo = re.match(pattern, node.name)
> if mo:
> extra_files.pop(extra_files.index(pattern))
> - return 0
> - print "Found unexpected disk object:", node.name
> - raise svntest.main.SVNTreeUnequal
> + break
> + else:
> + print "Found unexpected disk object:", node.name
> + raise svntest.main.SVNTreeUnequal
>
> def no_wc_copy_overwrites(sbox):
> "svn cp PATH PATH cannot overwrite destination"
> Index: subversion/tests/clients/cmdline/diff_tests.py
> ===================================================================
> --- subversion/tests/clients/cmdline/diff_tests.py (revision 6931)
> +++ subversion/tests/clients/cmdline/diff_tests.py (working copy)
> @@ -727,11 +727,10 @@
>
> stdout, stderr = svntest.main.run_svn(None, 'diff', wc_dir)
>
> - failed_to_display = 0;
> for line in stdout:
> if (re_nodisplay.match(line)):
> - failed_to_display = 1;
> - if not failed_to_display:
> + break
> + else:
> raise svntest.Failure
>
> # Second diff use-case: 'svn diff -r1 wc' compares the wc against a
> @@ -739,11 +738,10 @@
>
> stdout, stderr = svntest.main.run_svn(None, 'diff', '-r', '1', wc_dir)
>
> - failed_to_display = 0;
> for line in stdout:
> if (re_nodisplay.match(line)):
> - failed_to_display = 1;
> - if not failed_to_display:
> + break
> + else:
> raise svntest.Failure
>
> # Now commit the local mod, creating rev 3.
> @@ -767,11 +765,10 @@
>
> stdout, stderr = svntest.main.run_svn(None, 'diff', '-r', '2:3', wc_dir)
>
> - failed_to_display = 0;
> for line in stdout:
> if (re_nodisplay.match(line)):
> - failed_to_display = 1;
> - if not failed_to_display:
> + break
> + else:
> raise svntest.Failure
>
>
> Index: subversion/tests/clients/cmdline/externals_tests.py
> ===================================================================
> --- subversion/tests/clients/cmdline/externals_tests.py (revision 6931)
> +++ subversion/tests/clients/cmdline/externals_tests.py (working copy)
> @@ -779,12 +779,10 @@
> out_lines, err_lines = svntest.main.run_svn (1, 'up', path)
> if (err_lines):
> m = re.compile(expected_err)
> - found_it = 0
> for line in err_lines:
> if m.match(line):
> - found_it = 1
> break
> - if not found_it:
> + else:
> raise svntest.Failure
>
> test_update(other_B_path, "Target dir '../foo' references '..'")
> Index: subversion/tests/clients/cmdline/prop_tests.py
> ===================================================================
> --- subversion/tests/clients/cmdline/prop_tests.py (revision 6931)
> +++ subversion/tests/clients/cmdline/prop_tests.py (working copy)
> @@ -314,11 +314,11 @@
> mo = re.match(pattern, node.name)
> if mo:
> extra_files.pop(extra_files.index(pattern)) # delete pattern from
> list
> - return
> + break
> + else:
> + print "Found unexpected disk object:", node.name
> + raise svntest.tree.SVNTreeUnequal
>
> - print "Found unexpected disk object:", node.name
> - raise svntest.tree.SVNTreeUnequal
> -
> def update_conflict_props(sbox):
> "update with conflicting props"
>
> Index: subversion/tests/clients/cmdline/stat_tests.py
> ===================================================================
> --- subversion/tests/clients/cmdline/stat_tests.py (revision 6931)
> +++ subversion/tests/clients/cmdline/stat_tests.py (working copy)
> @@ -316,7 +316,7 @@
> # problem.
> for line in stat_output:
> if line.find('newfile') != -1:
> - break;
> + break
> else:
> return 1
>
> @@ -449,12 +449,13 @@
> if err:
> return 1
>
> - saw_it = 0
> for line in out:
> if re.match("\\s+\\*.*crontab\\.root$", line):
> - saw_it = 1
> + break
> + else:
> + return 1
>
> - return not saw_it
> + return 0
>
>
> #----------------------------------------------------------------------
> @@ -515,13 +516,12 @@
> if err:
> return 1
>
> - saw_uninvited_parent_dir = 0
> for line in out:
> # The "/?" is just to allow for an optional trailing slash.
> if re.match("\\s+\\*.*\.other/?$", line):
> - saw_uninvited_parent_dir = 1
> + return 1
>
> - return saw_uninvited_parent_dir
> + return 0
>
>
> def status_on_forward_deletion(sbox):
> Index: subversion/tests/clients/cmdline/update_tests.py
> ===================================================================
> --- subversion/tests/clients/cmdline/update_tests.py (revision 6931)
> +++ subversion/tests/clients/cmdline/update_tests.py (working copy)
> @@ -521,11 +521,11 @@
> mo = re.match(pattern, node.name)
> if mo:
> extra_files.pop(extra_files.index(pattern)) # delete pattern from
> list
> - return 0
> + break
> + else:
> + print "Found unexpected disk object:", node.name
> + raise svntest.main.SVNTreeUnequal
>
> - print "Found unexpected disk object:", node.name
> - raise svntest.main.SVNTreeUnequal
> -
> def update_to_resolve_text_conflicts(sbox):
> "delete files and update to resolve text conflicts"
>
> @@ -646,9 +646,10 @@
> mo = re.match(pattern, node.name)
> if mo:
> extra_files.pop(extra_files.index(pattern))
> - return 0
> - print "Found unexpected disk object:", node.name
> - raise svntest.main.SVNTreeUnequal
> + break
> + else:
> + print "Found unexpected disk object:", node.name
> + raise svntest.main.SVNTreeUnequal
>
> def update_delete_modified_files(sbox):
> "update that deletes modified files"
>
> --
> COMPUTERBILD 15/03: Premium-e-mail-Dienste im Test
> --------------------------------------------------
> 1. GMX TopMail - Platz 1 und Testsieger!
> 2. GMX ProMail - Platz 2 und Preis-Qualitätssieger!
> 3. Arcor - 4. web.de - 5. T-Online - 6. freenet.de - 7. daybyday - 8. e-Post
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
> For additional commands, e-mail: dev-help@subversion.tigris.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Tue Sep 9 15:02:35 2003

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.