[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, version 4

From: <kfogel_at_collab.net>
Date: 2005-07-06 21:00:35 CEST

You're going to hate me for this, Vivek, but I have an idea:

This dependency on the 'date' command is really bothering me. It's
going to be a portability nightmare. Of course, constructing the
dates by hand using Python's datetime.strftime() is also not reliably
consistent, according to http://docs.python.org/lib/node252.html.

So what should we do?

Here is what I propose: make the commits, but then hard set the
svn:date properties on those commits to some known date string, one
for which we can hardcode the appropriate format strings in the tests.

Of course, setting svn:date means activating pre-revprop-change hook.
But we wanted a portable hook setup framework for the regression tests
anyway, so I think that's more reasonable to depend on than the
existence of the 'date' command on the system.

Thoughts?

-Karl

Vivek <vivek@collab.net> writes:
> [[[
> Create a new file for 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,179 @@
> +#!/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) 2005 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, re
> +
> +# 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.
> +
> +local_time = list(time.localtime())
> +local_time[2] += 2 #day
> +local_time[3] += 2 #hour
> +local_time = tuple(local_time)
> +
> +time_array = [
> + time.strftime('%Y-%m-%d', local_time),
> + time.strftime('%H:%M', local_time),
> + time.strftime('%Y-%m-%d %H:%M', local_time),
> + time.strftime("%H:%M:%S", local_time)+'.000000',
> + time.strftime('%Y%m%dT%H%M', local_time),
> + time.strftime('%Y%m%dT%H%M%z', local_time),
> + time.strftime('%Y-%m-%dT%H:%M%z', local_time),
> + time.strftime('%Y-%m-%d %H:%M %z', local_time),
> + time.strftime('%Y-%m-%dT%H:%M', local_time),
> + time.strftime('%Y-%m-%d %H:%M', local_time),
> + ]
> +
> +######################################################################
> +# 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, len(time_array)):
> + out, err = svntest.main.run_svn(1, 'log', mu_path, '-r',
> + '{' + str(time_array[i]) + '}'
> + )
> + if not(err == [] and re.match('Log message for revision 1.*', out[3])):
> + 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')
> +
> + #If we don't get anything from popen, just skip the test
> + date_file = None
> + date_file = os.popen("date --iso-8601=seconds -d '+2 hours'")
> + if date_file is None: Skip
> +
> + # The Success Case: output and no errors.
> + arg = date_file.readline()
> + svntest.actions.run_and_verify_svn('cat a file using GNU date',
> + ["This is the file 'mu'.\n"], 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()
> + 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 repos. If we try
> +# 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')
> + open(hook, 'w').write("#!/bin/sh\n\nexit 0\n")
> + os.chmod(hook, 0755)
> + elif sys.platform == 'win32':
> + hook = os.path.join(svntest.main.current_repo_dir,
> + 'hooks', 'pre-revprop-change.bat')
> + open(hook, 'w').write("@exit 0\n")
> +
> + # Test: everything ok?
> + arg = time.strftime('%Y-%m-%d %H:%M', local_time)
> + svntest.actions.run_and_verify_svn('Cat a file with svn:date property set',
> + ["This is the file 'mu'.\n"], None,
> + '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, None, '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 not err[len(err)-1] == '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, None,
> + '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'.\n"], [],
> + 'cat', '-r',
> + '{' + str(arg) + '}', mu_path)
> +
> +
> +########################################################################
> +# Run the tests
> +
> +
> +# list all tests here, starting with None:
> +
> +test_list = [ None,
> + log_with_date_option,
> + cat_with_date_option,
> + 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.
>
> ---------------------------------------------------------------------
> 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 Wed Jul 6 21:49:00 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.