[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [compass/master] Added some testing scripts
commit 70e369c263be79d87f6d752fc1b46ae5f70393c5
Author: Chris Wacek <cwacek@xxxxxxxxxxxxxxxxx>
Date: Fri Dec 21 15:58:38 2012 -0500
Added some testing scripts
---
testing/README | 13 +++++++++
testing/check.py | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
testing/test.sh | 41 ++++++++++++++++++++++++++++++
3 files changed, 127 insertions(+), 0 deletions(-)
diff --git a/testing/README b/testing/README
new file mode 100644
index 0000000..9457b1e
--- /dev/null
+++ b/testing/README
@@ -0,0 +1,13 @@
+
+These are a set of scripts designed to makes sure that any
+changes I have made don't change the behavior of the original
+compass.py. test.sh will run a series of command line switches
+at compass.py, and save the output in a series of named test
+files.
+check.py will take two test names and compare the output
+from those tests to see if they match.
+
+
+Note: Sometimes a test will fail even though the output is correct
+because the sorting works differently in my revised version and
+elements with the same value don't always occur in the same order.
diff --git a/testing/check.py b/testing/check.py
new file mode 100755
index 0000000..c15583c
--- /dev/null
+++ b/testing/check.py
@@ -0,0 +1,73 @@
+#!/usr/bin/python
+
+import os
+import sys
+
+def colored(s,col):
+ if col == "red":
+ return "\033[31m" + s + "\033[0m"
+ elif col == "green":
+ return "\033[36m" + s + "\033[0m"
+ else:
+ return s
+
+def usage():
+ sys.stderr.write("Check and see if output matches between two sets of test files\n")
+ sys.stderr.write("Usage: check.py <testfile_dir> <test_label_1> <test_label_2> \n")
+ sys.exit(-1)
+
+
+def run():
+
+ if len(sys.argv) < 3:
+ usage()
+
+ filedir = sys.argv[1]
+ a = sys.argv[2]
+ b = sys.argv[3]
+ a_files = {}
+ b_files = {}
+ max_test = 0
+
+
+ files = os.listdir(filedir)
+
+ for f in files:
+ if f.split(".")[0] == a:
+ a_files[int( f.split(".")[1] )] = f
+ if f.split(".")[0] == b:
+ b_files[int(f.split(".")[1])] = f
+
+
+ if int(f.split(".")[1]) > max_test:
+ max_test = int(f.split('.')[1])
+
+ for i in xrange(1,max_test):
+ sys.stdout.write("Testing '{0}.{2}' against '{1}.{2}': ".format(a,b,i))
+
+ try:
+ a_in = open("{0}/{1}".format(filedir,a_files[i])).readlines()
+ b_in = open("{0}/{1}".format(filedir,b_files[i])).readlines()
+ except IOError,e:
+ sys.stdout.write("{0} [{1}]\n".format(colored("Fail","red"),e))
+ else:
+ i = 0
+ fail = False
+
+ for comp_a,comp_b in zip(a_in,b_in):
+ i += 1
+ for field_a, field_b in zip(comp_a.split(),comp_b.split()):
+ if field_a.lower() != field_b.lower():
+ sys.stdout.write("{0} [{1}]\n".format(colored("Fail","red"),"Line {0} doesn't match.".format(i)))
+ fail = True
+ break
+
+ if fail:
+ break
+
+ if not fail:
+ sys.stdout.write("{0}\n".format(colored("Pass","green")))
+
+
+if __name__ == "__main__":
+ run()
diff --git a/testing/test.sh b/testing/test.sh
new file mode 100755
index 0000000..5aa9284
--- /dev/null
+++ b/testing/test.sh
@@ -0,0 +1,41 @@
+#!/bin/bash
+
+# This is intended to run a bunch of options against compass.py and dump
+# the output to a file.
+
+if [[ $# -lt 3 ]]; then
+ echo "Usage: test.sh <compass_py_loc> <scratch_dir> <test_name>"
+ exit 1
+fi
+
+scratch="$2"
+[[ -d $scratch ]] || echo "'$scratch' is not a directory" || exit 1
+[[ -f $1 ]] || echo "'$1' is not a file" || exit 1
+
+name="$3"
+
+i=1
+
+bin="python $1"
+declare -a testcases=(
+ ''
+ '-i'
+ '-e'
+ '-a 3320'
+ '-a 3320 -i -e -l'
+ '-c US'
+ '-c US -g'
+ '-c US -A'
+ '-g -e'
+ '--almost-fast-exits-only'
+ '--fast-exits-only'
+ '-l'
+ '--almost-fast-exits-only -c DE'
+ '-t 100 -s'
+ )
+
+for i in $(seq 0 "${#testcases[@]}"); do
+ $bin ${testcases[$i]} > "$scratch/$name.$i"
+done
+
+
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits