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

Re: [PATCH] date_tests.py

From: Brian W. Fitzpatrick <fitz_at_collab.net>
Date: 2005-06-16 20:02:11 CEST

Comments inline

On Tue, 2005-06-14 at 02:37 -0700, vivek@collab.net wrote:
> [[[
> Create a new file for testing date related issues.
>
> * subversion/tests/clients/cmdline/date_tests.py: New File.
> ]]]
Index: subversion/tests/clients/cmdline/date_tests.py
> ===================================================================
> --- subversion/tests/clients/cmdline/date_tests.py (revision 0)
> +++ subversion/tests/clients/cmdline/date_tests.py (revision 0)
> @@ -0,0 +1,176 @@
> +#!/usr/bin/env python
> +#
> +# date_tests.py: testing date cases.
> +#
> +# Subversion is a tool for revision control.
> +# See http://subversion.tigris.org for more information.
> +#
> +#
====================================================================
> +# Copyright (c) 2000-2004 CollabNet. All rights reserved.
> +#
> +# This software is licensed as described in the file COPYING, which
> +# you should have received as part of this distribution. The terms
> +# are also available at http://subversion.tigris.org/license-1.html.
> +# If newer versions of this license are posted there, you may use a
> +# newer version instead, at your option.
> +#
>
+######################################################################
> +
> +# General modules
> +import os, time
> +
> +# Our testing module
> +import svntest
> +
> +# (abbreviation)
> +Skip = svntest.testcase.Skip
> +XFail = svntest.testcase.XFail
> +Item = svntest.wc.StateItem
> +
>
+#----------------------------------------------------------------------
> +# Is Subversion A Day Early? Yes, so modify test time accordingly.
> +
> +t = list(time.localtime())
> +t[2] += 2 #day
> +t[3] += 2 #hour
> +t = tuple(t)
> +
> +time_array = [
> + time.strftime('%Y-%m-%d', t),
> + time.strftime('%H:%M', t),
> + time.strftime('%Y-%m-%d %H:%M', t),
> + time.strftime("%H:%M:%S", t)+'.000000',
> + time.strftime('%Y%m%dT%H%M', t),
> + time.strftime('%Y%m%dT%H%M%z', t),
> + time.strftime('%Y-%m-%dT%H:%M%z', t),
> + time.strftime('%Y-%m-%d %H:%M %z', t),
> + time.strftime('%Y-%m-%dT%H:%M', t),
> + time.strftime('%Y-%m-%d %H:%M', t),
> + ]
> +
>
+######################################################################
> +# Tests
> +#
> +# Each test must return on success or raise on failure.
> +
>
+#----------------------------------------------------------------------
> +
>
+#----------------------------------------------------------------------
> +# Test log with date option.
> +def log_with_date_option(sbox):
> + "get log with -r {date}"
> + sbox.build()
> +
> + wc_dir = sbox.wc_dir
> +
> + mu_path = os.path.join(wc_dir, 'A/mu')
> +
> + for i in range(0,10):

Don't use 10, use len(time_array)

> + out, err = svntest.main.run_svn(None,'log', mu_path, '-r', '{' +
> + str(time_array[i]) + '}'
> + )
> + if err != '' and out[3] != 'Log message for revision 1.\n' :

instead of '!=' use 'if not' ...

> + raise svntest.Failure
> +
>
+#----------------------------------------------------------------------
> +# The output of GNU date was not being accepted by svn commands
> +# Test the fix.
> +def cat_with_date_option(sbox):
> + "use GNU date command in revision input"
> + sbox.build()
> +
> + wc_dir = sbox.wc_dir
> +
> + mu_path = os.path.join(wc_dir, 'A/mu')
> +
> + # The Success Case: output and no errors.
> + arg = os.popen("date --iso-8601=seconds -d '+2 hours'").readline()

Why are you using popen for this instead of the python time functions?

> + svntest.actions.run_and_verify_svn('cat a file using GNU date',
> + ["This is the file 'mu'."],
None,
> + 'cat', '-r', '{' +
> + str(arg).strip('\n') + '}',
mu_path)
> +
> + # The Failure Case: no output and some
errors.
> + arg = os.popen("date --iso-8601=seconds -d '-2 hours'").readline
()

Same here.

> + svntest.actions.run_and_verify_svn('cat a file using GNU date',
> + [], svntest.SVNAnyOutput,
'cat', '-r',
> + '{' + str(arg).strip('\n') +
'}',
> + mu_path)
> +
>
+#----------------------------------------------------------------------
> +# Date is stored as an unversiond property in the reop. If we try

s/reop/repository/

> +# to meddle with it, we may land in trouble. Here is a test.
> +def cat_with_date_prop_modified
(sbox):
> + "change the date property"
> +
> + sbox.build()
> + mu_path = os.path.join(sbox.wc_dir, 'A/mu')
> +
> + # Create the revprop-change hook
> + if os.name == 'posix':
> + hook = os.path.join(svntest.main.current_repo_dir, 'hooks',
> + 'pre-revprop-change')
> + svntest.main.file_append(hook, "#!/bin/sh\n\nexit 0\n")

Why are you using svntest.main.file_append here instead of open().write
('foo')?

> + os.chmod(hook, 0755)
> + elif sys.platform == 'win32':
> + hook = os.path.join(svntest.main.current_repo_dir,
> + 'hooks', 'pre-revprop-change.bat')
> + svntest.main.file_append(hook, "@exit 0\n")

Same here.

> + # Test: everything ok?
> + arg = time.strftime('%Y-%m-%d %H:%M',t)

Here you use strftime to get the time and above you use popen. Why?

> + svntest.actions.run_and_verify_svn('Cat a file with svn:date
property set',
> + ["This is the file 'mu'."],[],
> + 'cat', '-r',
> + '{' + str(arg) + '}',
mu_path)
> +
> + # Set: property svn:date with a bogus date
> + out = ["property 'svn:date' set on repository revision 1\n"]
> + svntest.actions.run_and_verify_svn(None, out, [], 'propset',
> + "--revprop", "-r", '1',
> + '-R' , 'svn:date',
> + time.strftime('%Y-%m-%dT%H:%M:%
S'),
> + sbox.wc_dir)
> +
> + e_out, err = svntest.main.run_svn (1, 'cat', '-r',
> + '{' + str(arg) + '}', mu_path)
> + if err.pop() != 'svn: Bogus date\n':
> + raise svntest.Failure
> +
> + # We did a mistake in setting up the date.
> + # Can we reset it? Format is in
libsvn_subr/time.c
> + svntest.actions.run_and_verify_svn(None, out, [],
> + 'propset', "--revprop", "-r",
'1',
> + '-R' , 'svn:date',
> + time.strftime('%Y-%m-%dT%H:%M:%
S')
> + +'.000000Z',
> + sbox.wc_dir)
> +
> + # Yes, we can!
> + svntest.actions.run_and_verify_svn('Cat a file with svn:date
property set',
> + ["This is the file 'mu'."],[],
> + 'cat', '-r',
> + '{' + str(arg) + '}',
mu_path)
> +
> +
>
+########################################################################
> +# Run the tests
> +
> +
> +# list all tests here, starting with
None:
> +
> +test_list = [ None,
> + log_with_date_option,
> + Skip(cat_with_date_option, os.name == 'win32'),
> + # If we learn how to write a pre-revprop-change hook
for
> + # non-Posix platforms, we won't have to skip here:
> + Skip(cat_with_date_prop_modified,
> + (os.name != 'posix' and sys.platform != 'win32')),
> + ]
> +
> +if __name__ == '__main__':
> + svntest.main.run_tests(test_list)
> + # NOTREACHED
> +
> +
> +### End of file.

-Fitz

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Thu Jun 16 20:02:20 2005

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.