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

[PATCH] Making 'Skip' to accept lambda function

From: Kamesh Jayachandran <kamesh_at_collab.net>
Date: 2007-06-08 10:22:21 CEST

Hi,
Few days back Malcom and I identified the problem with Skip not being
able to accept callable lambda function.
This causes misunderstanding from the developers expecting Skip to
behave like Xfail and after few lost hours understand that 'Skip'
accepts a bool not a callable function.

I am attaching a patch in this regard. Once it is checked in I can work
on making 'raise Skip' inside tests, to use 'Skip' marker in the test_list.

Now the problem is, '--list' switch to tests.

As we don't know the type(skip/no-skip) of Test till it executes and as
'--list' is not a execution mode, this patch would mark all the Skip
tests to be 'SKIP'.

It is similar to 'XFAIL'.

I am snipping the --list output of special_tests.py on my linux box,
where this tests are not skipped.

<snip prior to applying the patch>
Test # Mode Test Description
------ ----- ----------------
  1 general symlink handling
  2 replace a normal file with a special file
  3 import and export a symlink
  4 'svn cp dir1 dir2' which contains a symlink
  5 replace a special file with a non-special file
  6 remove a symlink
  7 merge symlink into file
  8 merge file into symlink
  9 checkout a repository containing symlinks
 10 XFAIL diff a symlink to a directory
 11 checkout repository with unknown special file type
 12 replace a special file with a directory
 13 symlink obstructs incoming delete
</snip>

<snip after applying the patch>
Test # Mode Test Description
------ ----- ----------------
  1 SKIP general symlink handling
  2 SKIP replace a normal file with a special file
  3 SKIP import and export a symlink
  4 SKIP 'svn cp dir1 dir2' which contains a symlink
  5 SKIP replace a special file with a non-special file
  6 SKIP remove a symlink
  7 SKIP merge symlink into file
  8 SKIP merge file into symlink
  9 checkout a repository containing symlinks
 10 SKIP diff a symlink to a directory
 11 checkout repository with unknown special file type
 12 replace a special file with a directory
 13 SKIP symlink obstructs incoming delete
</snip>

Let me know your thoughts.

With regards
Kamesh Jayachandran

Index: subversion/tests/cmdline/svntest/testcase.py
===================================================================
--- subversion/tests/cmdline/svntest/testcase.py (revision 25318)
+++ subversion/tests/cmdline/svntest/testcase.py (working copy)
@@ -159,25 +159,33 @@
 class Skip(TestCase):
   """A test that will be skipped if condition COND is true."""
 
- def __init__(self, test_case, cond=1):
+ def __init__(self, test_case, cond_func=lambda:1):
+ """Create an Skip instance based on TEST_CASE. COND_FUNC is a
+ callable that is evaluated at test run time and should return a
+ boolean value. If COND_FUNC returns true, then TEST_CASE is
+ skipped; otherwise, TEST_CASE is run normally.
+ The evaluation of COND_FUNC is deferred so that it can base its
+ decision on useful bits of information that are not available at
+ __init__ time (like the fact that we're running over a
+ particular RA layer)."""
+
     TestCase.__init__(self)
     self.test_case = create_test_case(test_case)
- self.cond = cond
- if self.cond:
- self._list_mode_text = 'SKIP'
+ self.cond_func = cond_func
+ self._list_mode_text = 'SKIP'
     # Delegate most methods to self.test_case:
     self.get_description = self.test_case.get_description
     self.get_sandbox_name = self.test_case.get_sandbox_name
     self.convert_result = self.test_case.convert_result
 
   def need_sandbox(self):
- if self.cond:
+ if self.cond_func():
       return 0
     else:
       return self.test_case.need_sandbox()
 
   def run(self, sandbox=None):
- if self.cond:
+ if self.cond_func():
       raise svntest.Skip
     elif self.need_sandbox():
       return self.test_case.run(sandbox=sandbox)
Index: subversion/tests/cmdline/svntest/main.py
===================================================================
--- subversion/tests/cmdline/svntest/main.py (revision 25318)
+++ subversion/tests/cmdline/svntest/main.py (working copy)
@@ -667,6 +667,9 @@
 def is_os_windows():
   return (os.name == 'nt')
 
+def is_non_posix_os():
+ return (os.name != 'posix')
+
 ######################################################################
 # Sandbox handling
 
Index: subversion/tests/cmdline/utf8_tests.py
===================================================================
--- subversion/tests/cmdline/utf8_tests.py (revision 25318)
+++ subversion/tests/cmdline/utf8_tests.py (working copy)
@@ -146,7 +146,7 @@
 
 # list all tests here, starting with None:
 test_list = [ None,
- Skip(basic_utf8_conversion, 1)
+ Skip(basic_utf8_conversion)
              ]
 
 if __name__ == '__main__':
Index: subversion/tests/cmdline/commit_tests.py
===================================================================
--- subversion/tests/cmdline/commit_tests.py (revision 25318)
+++ subversion/tests/cmdline/commit_tests.py (working copy)
@@ -33,6 +33,9 @@
 # Utilities
 #
 
+def is_non_posix_os_or_cygwin_platform():
+ return svntest.main.is_non_posix_os() or sys.platform == 'cygwin'
+
 def get_standard_state(wc_dir):
   """Return a status list reflecting the local mods made by
   make_standard_slew_of_changes()."""
@@ -2415,7 +2418,7 @@
               commit_with_bad_log_message,
               from_wc_top_with_bad_editor,
               mods_in_schedule_delete,
- Skip(tab_test, (os.name != 'posix' or sys.platform == 'cygwin')),
+ Skip(tab_test, is_non_posix_os_or_cygwin_platform),
               local_mods_are_not_commits,
               post_commit_hook_test,
               commit_same_folder_in_targets,
Index: subversion/tests/cmdline/prop_tests.py
===================================================================
--- subversion/tests/cmdline/prop_tests.py (revision 25318)
+++ subversion/tests/cmdline/prop_tests.py (working copy)
@@ -28,6 +28,8 @@
 XFail = svntest.testcase.XFail
 Item = svntest.wc.StateItem
 
+def is_non_posix_and_non_windows_os():
+ return svntest.main.is_non_posix_os() and sys.platform != 'win32'
 
 # Helper functions
 def check_prop(name, path, exp_out):
@@ -1366,8 +1368,7 @@
               copy_inherits_special_props,
               # If we learn how to write a pre-revprop-change hook for
               # non-Posix platforms, we won't have to skip here:
- Skip(revprop_change, (os.name != 'posix'
- and sys.platform != 'win32')),
+ Skip(revprop_change, is_non_posix_and_non_windows_os),
               prop_value_conversions,
               binary_props,
               recursive_base_wc_ops,
Index: subversion/tests/cmdline/schedule_tests.py
===================================================================
--- subversion/tests/cmdline/schedule_tests.py (revision 25318)
+++ subversion/tests/cmdline/schedule_tests.py (working copy)
@@ -637,7 +637,7 @@
               revert_add_files,
               revert_add_directories,
               revert_nested_adds,
- Skip(revert_add_executable, (os.name != 'posix')),
+ Skip(revert_add_executable, svntest.main.is_non_posix_os),
               revert_delete_files,
               revert_delete_dirs,
               unschedule_missing_added,
Index: subversion/tests/cmdline/special_tests.py
===================================================================
--- subversion/tests/cmdline/special_tests.py (revision 25318)
+++ subversion/tests/cmdline/special_tests.py (working copy)
@@ -628,19 +628,19 @@
 
 # list all tests here, starting with None:
 test_list = [ None,
- Skip(general_symlink, (os.name != 'posix')),
- Skip(replace_file_with_symlink, (os.name != 'posix')),
- Skip(import_export_symlink, (os.name != 'posix')),
- Skip(copy_tree_with_symlink, (os.name != 'posix')),
- Skip(replace_symlink_with_file, (os.name != 'posix')),
- Skip(remove_symlink, (os.name != 'posix')),
- Skip(merge_symlink_into_file, (os.name != 'posix')),
- Skip(merge_file_into_symlink, (os.name != 'posix')),
+ Skip(general_symlink, svntest.main.is_non_posix_os),
+ Skip(replace_file_with_symlink, svntest.main.is_non_posix_os),
+ Skip(import_export_symlink, svntest.main.is_non_posix_os),
+ Skip(copy_tree_with_symlink, svntest.main.is_non_posix_os),
+ Skip(replace_symlink_with_file, svntest.main.is_non_posix_os),
+ Skip(remove_symlink, svntest.main.is_non_posix_os),
+ Skip(merge_symlink_into_file, svntest.main.is_non_posix_os),
+ Skip(merge_file_into_symlink, svntest.main.is_non_posix_os),
               checkout_repo_with_symlinks,
- XFail(Skip(diff_symlink_to_dir, (os.name != 'posix'))),
+ XFail(Skip(diff_symlink_to_dir, svntest.main.is_non_posix_os)),
               checkout_repo_with_unknown_special_type,
               replace_symlink_with_dir,
- Skip(update_obstructing_symlink, (os.name != 'posix')),
+ Skip(update_obstructing_symlink, svntest.main.is_non_posix_os),
              ]
 
 if __name__ == '__main__':
Index: subversion/tests/cmdline/stat_tests.py
===================================================================
--- subversion/tests/cmdline/stat_tests.py (revision 25318)
+++ subversion/tests/cmdline/stat_tests.py (working copy)
@@ -1564,7 +1564,7 @@
               status_shows_all_in_current_dir,
               status_missing_file,
               status_type_change,
- Skip(status_type_change_to_symlink, (os.name != 'posix')),
+ Skip(status_type_change_to_symlink, svntest.main.is_non_posix_os),
               status_with_new_files_pending,
               status_for_unignored_file,
               status_for_nonexistent_file,
Index: subversion/tests/cmdline/copy_tests.py
===================================================================
--- subversion/tests/cmdline/copy_tests.py (revision 25318)
+++ subversion/tests/cmdline/copy_tests.py (working copy)
@@ -3702,7 +3702,7 @@
               copy_files_with_properties,
               copy_delete_commit,
               mv_and_revert_directory,
- Skip(copy_preserve_executable_bit, (os.name != 'posix')),
+ Skip(copy_preserve_executable_bit, svntest.main.is_non_posix_os),
               wc_to_repos,
               repos_to_wc,
               copy_to_root,
Index: subversion/tests/cmdline/lock_tests.py
===================================================================
--- subversion/tests/cmdline/lock_tests.py (revision 25318)
+++ subversion/tests/cmdline/lock_tests.py (working copy)
@@ -1552,8 +1552,8 @@
               lock_several_files,
               lock_switched_files,
               lock_uri_encoded,
- Skip(lock_and_exebit1, (os.name != 'posix')),
- Skip(lock_and_exebit2, (os.name != 'posix')),
+ Skip(lock_and_exebit1, svntest.main.is_non_posix_os),
+ Skip(lock_and_exebit2, svntest.main.is_non_posix_os),
               commit_xml_unsafe_file_unlock,
               repos_lock_with_info,
               unlock_already_unlocked_files,
Index: subversion/tests/cmdline/import_tests.py
===================================================================
--- subversion/tests/cmdline/import_tests.py (revision 25318)
+++ subversion/tests/cmdline/import_tests.py (working copy)
@@ -369,7 +369,7 @@
 
 # list all tests here, starting with None:
 test_list = [ None,
- Skip(import_executable, (os.name != 'posix')),
+ Skip(import_executable, svntest.main.is_non_posix_os),
               import_ignores,
               import_avoid_empty_revision,
               import_no_ignores,

[[[
Skip condition is made as a lamda function.

* subversion/tests/cmdline/svntest/testcase.py
  (Skip.__init__): Signature change cond -> cond_func a lamda function callable
   at test runtime.
  (Skip.need_sandbox): Call cond_func.
  (Skip.run): Call cond_func.

* subversion/tests/cmdline/svntest/main.py
  (is_non_posix_os): New function.

* subversion/tests/cmdline/utf8_tests.py
  (test_list): No need to explicitly state a condition to be True as
  it is True by default.

* subversion/tests/cmdline/commit_tests.py
  (is_non_posix_os_or_cygwin_platform): New function.
  (test_list): Create Skip instance with a lambda function.

* subversion/tests/cmdline/prop_tests.py
  (is_non_posix_and_non_windows_os): New function.
  (test_list): Create Skip instance with a lambda function.

* subversion/tests/cmdline/schedule_tests.py
* subversion/tests/cmdline/special_tests.py
* subversion/tests/cmdline/stat_tests.py
* subversion/tests/cmdline/copy_tests.py
* subversion/tests/cmdline/lock_tests.py
* subversion/tests/cmdline/import_tests.py
  (test_list): Create Skip instance with a lambda function.

Suggested by: malcolm
]]]

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Fri Jun 8 10:33:06 2007

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.