Skip to content

Commit

Permalink
Removing old, unused, testing classes
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanwhite committed Apr 17, 2015
1 parent 88a32aa commit 2632b03
Showing 1 changed file with 0 additions and 114 deletions.
114 changes: 0 additions & 114 deletions lib/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,120 +21,6 @@

TEST_ENGINES = dict()


class ScriptTest(unittest.TestCase):
"""Automates the process of creating unit tests for Retriever scripts.
Uses the Python unittest module."""
def strvalue(self, value, col_num):
"""Returns a string representing the cleaned value from a SELECT
statement, for use in tests.
Arguments: value -- the value to be converted,
col_num -- the column number of the value (starting from 0)
col_num is not used in this function, but may be
useful when overriding this function
"""
if value != None:
if isinstance(value, str) or isinstance(value, unicode):
# If the value is a string or unicode, it's not a number and
# should be surrounded by quotes.
return '"' + str(value) + '"'
elif value == 0:
return "0.00"
elif isinstance(value, Decimal) or (Decimal("-0.01") <
Decimal(str(value)) <
Decimal("0.01")):
try:
if Decimal("-0.01") < Decimal(str(value)) < Decimal("0.01"):
dec = len(str(value).split('.')[-1].strip('0')) - 1
value = ("%." + str(dec) + "e") % value
value = str(value)
strippedvalue = value.split("e")
return (strippedvalue[0].rstrip("0") +
"e" + strippedvalue[1])
except:
pass

value = str(value).rstrip('0')
if not '.' in value:
value += ".0"
if len(value.split('.')) == 2:
while len(value.split('.')[-1]) < 2:
value = value + "0"
return value
else:
value = str(value)
if '.' in value:
value = value.rstrip('0')
else:
value += ".0"
if len(str(value).split('.')) == 2:
while len(str(value).split('.')[-1]) < 2:
value = str(value) + "0"
return str(value)
else:
return str(value)
else:
return ""

def default_test(self, script, tables, include_pk = False):
"""The default unit test. Tests in ScriptTest classes can simply call
this function with the appropriate paramaters. The "script" property
should be an instance of Script, and tables is a list consisting of
tuples in the following format:
(table name, MD5 sum, [order by statement])
"""
for engine_letter in [engine.abbreviation for engine in ENGINES_TO_TEST]:
engine = TEST_ENGINES[engine_letter]
engine.script = script

print "Testing with " + engine.name
script.download(engine)

print "Testing data . . ."

for table in tables:
tablename = table[0]
checksum = table[1]
if len(table) > 2:
orderby = table[2]

cursor = engine.connection.cursor()
engine.table.table_name = tablename
select_statement = "SELECT * FROM " + engine.table_name()
if orderby:
select_statement += " ORDER BY " + orderby
select_statement += ";"
cursor.execute(select_statement)
engine.connection.commit()

lines = []
for row in cursor.fetchall():
if include_pk:
start = 0
else:
start = 1
newline = ','.join([self.strvalue(row[i], i - 1)
for i
in range(start, len(row))])
lines.append(newline + "\r\n")

# If a test fails, you can temporarily uncomment this line
# to print each line that doesn't match up together with the
# line from the test file; this can be useful to find the
# discrepancies
# checkagainstfile(lines, "PanTHERIA_manual.txt")

lines = ''.join(lines)
sum = getmd5(lines)

self.assertEqual(sum, checksum)


def name_matches(scripts, arg):
matches = []
for script in scripts:
Expand Down

0 comments on commit 2632b03

Please sign in to comment.