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

HEADS UP: cmdline test factory

From: Neels Janosch Hofmeyr <neels_at_elego.de>
Date: Sun, 21 Jun 2009 00:59:20 +0200

Hi all,

don't worry, this is just a new feature. It might save you quite some time,
that's why I'm taking the liberty to shout.

I recently added subversion/cmdline/svntest/factory.py, which can write a
test for you. Let me illustrate how cmpilato could have written the test he
committed in r38101, probably in less time than he did.

Mike's test, in essence, does this:
  echo "This represents a binary file\n" >> iota
  svn ci
  svn lock -m 'lock & load' iota

In cmdline test lingo, he wrote this instead:
def lock_funky_comment_chars(sbox):
  "lock a file using a comment with xml special chars"

  wc_dir = sbox.wc_dir

  # lock a file as wc_author
  fname = 'iota'
  file_path = os.path.join(sbox.wc_dir, fname)

  svntest.main.file_append(file_path, "This represents a binary file\n")
  svntest.main.run_svn(None, 'commit',
                       '-m', '', file_path)
  svntest.actions.run_and_verify_svn(None, ".*locked by user", [], 'lock',
                                     '-m', 'lock & load', file_path)

What if I told you that he could just have written the simple and short
sequence of shell commands, run them through some py, and would have gotten
an optimized cmdline test script that does waterproof verification?

Well, I'm telling you, now :)

This is how I implemented the same test cmpilato wrote in about two minutes

def mine(sbox):
  "lock a file using a comment with xml special chars"
  svntest.factory.make(sbox, """
                       echo "This represents a binary file\\n" >> iota
                       svn ci
                       svn lock -m 'lock & load' iota
(Note that I had to double-escape the '\n' to '\\n' because of python
parsing it before factory can.)

I ran that test (called "mine" for educational purposes :P) and factory spat
out this code for me, on stdout:

$ ./lock_tests.py mine
  wc_dir = sbox.wc_dir

  iota = os.path.join(wc_dir, 'iota')

  # echo "This represents a binary file\n" >> iota
  main.file_append(iota, 'This represents a binary file\n')

  # svn ci
  expected_output = svntest.wc.State(wc_dir, {
    'iota' : Item(verb='Sending'),

  expected_status = actions.get_virginal_state(wc_dir, 1)
  expected_status.tweak('iota', wc_rev='2')

  actions.run_and_verify_commit(wc_dir, expected_output, expected_status,
    None, wc_dir)

  # svn lock -m 'lock & load' iota
  expected_stdout = ["'iota' locked by user 'jrandom'.\n"]

  actions.run_and_verify_svn2('OUTPUT', expected_stdout, [], 0, 'lock', '-m',
    'lock & load', iota)

  Remember, this only saves you typing. Doublecheck everything.

PASS: lock_tests.py 36: lock a file using a comment with xml special chars

There you go. Paste it back, comment out the original factory call (for
later reference), maybe adjust some output matching with wildcards and done.

Note that the factory test runs a full run_and_verify_commit() instead of
just a run_svn(). That can be seen as good (stricter) or bad (too elaborate
for something that doesn't need checking really, the case here I guess).

But I think this factory is pretty nice. Saves you a lot of typing. All you
need to do is paste, read and tweak. (We can also add some indicators to
mark non-strict sections of the test... comments/tweaks welcome!)

Find more elaborate info in a verbose comment at the top of svntest/factory.py.

Thank you for your attention. :)


Received on 2009-06-21 00:59:51 CEST

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.