The following code fails to run, but if I remove the line "datafile = sys.argv[1]" it works fine. I invoke the script as:
generateTests.py full-path-to-file
The error message is below the code sample. Could someone explain what is wrong with doing this?
#!/usr/bin/python
import sys
import unittest
import xmlrunner
mydata = [["VectorAdd", "56"],["MatrixMul", "101"]]
class TestWithDataFiles(unittest.TestCase):
def setUp(self):
print("Initializing...")
@classmethod
def setUpClass(cls):
# Now call unittest version
super(TestWithDataFiles, cls).setUpClass()
print("Class setup...")
datafile = sys.argv[1]
def myClass(TestWithDataFiles):
@classmethod
def setUpClass(cls):
# Call TestWithDataFiles class setup first
super(myClass, cls).setUpClass()
def test_genHSAILRunToBreakpoint(testData):
def test_HSAILRunToBreakpoint(self):
print("%s"%testData[0])
print(self)
return test_HSAILRunToBreakpoint
def test_genHSAILRunToTwoBreakpoints(testData):
def test_HSAILRunToTwoBreakpoints(self):
print("%s"%testData[1])
return test_HSAILRunToTwoBreakpoints
if __name__ == '__main__':
for testData in mydata:
test_name = "test_HSAILRunToBreakpoint_%s"%testData[0]
test = test_genHSAILRunToBreakpoint(testData)
setattr(TestWithDataFiles, test_name, test)
test_name = "test_HSAILRunToTwoBreakpoints_%s"%testData[0]
test = test_genHSAILRunToTwoBreakpoints(testData)
setattr(TestWithDataFiles, test_name, test)
unittest.main(testRunner=xmlrunner.XMLTestRunner(output="testlog"))
python ~/bin/generateTests.py ~/.profile
Traceback (most recent call last):
File "/home/bgriffin/bin/generateTests.py", line 47, in <module>
unittest.main(testRunner=xmlrunner.XMLTestRunner(output="testlog"))
File "/usr/lib/python2.7/unittest/main.py", line 94, in __init__
self.parseArgs(argv)
File "/usr/lib/python2.7/unittest/main.py", line 149, in parseArgs
self.createTests()
File "/usr/lib/python2.7/unittest/main.py", line 158, in createTests
self.module)
File "/usr/lib/python2.7/unittest/loader.py", line 130, in loadTestsFromNames
suites = [self.loadTestsFromName(name, module) for name in names]
File "/usr/lib/python2.7/unittest/loader.py", line 100, in loadTestsFromName
parent, obj = obj, getattr(obj, part)
AttributeError: 'module' object has no attribute '/home/bgriffin/'
The following code modifications still fail. Note that I tried using both test_name and test in the suite.addTests call, both have the same behavior.
#!/usr/bin/python
import argparse
import sys
import unittest
import xmlrunner
mydata = [["VectorAdd", "56"],["MatrixMul", "101"]]
class TestWithDataFiles(unittedst.TestCase):
def setUp(self):
print("Initializing...")
@classmethod
def setUpClass(cls):
# Now call unittest version
super(TestWithDataFiles, cls).setUpClass()
print("Class setup...")
dataFile = "teswt"
arg1 = sys.argv[1]
print(arg1)
def myClass(TestWithDataFiles):
@classmethod
def setUpClass(cls):
# Call TestWithDataFiles class setup first
super(myClass, cls).setUpClass()
def test_genHSAILRunToBreakpoint(testData):
def test_HSAILRunToBreakpoint(self):
print("%s"%testData[0])
print(self)
return test_HSAILRunToBreakpoint
def test_genHSAILRunToTwoBreakpoints(testData):
def test_HSAILRunToTwoBreakpoints(self):
print("%s"%testData[1])
return test_HSAILRunToTwoBreakpoints
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--useValgrind', help="run hsail-gdb through valgrind")
parser.add_argument('--branch', action='store', type=str, default="main", help="perforce branch to run tests from")
parser.add_argument('--datafiles', action='store', type=str, help="Comma separated list of test data files")
args = parser.parse_args()
print(args.datafiles)
suite = unittest.TestSuite()
for testData in mydata:
test_name = "test_HSAILRunToBreakpoint_%s"%testData[0]
test = test_genHSAILRunToBreakpoint(testData)
setattr(TestWithDataFiles, test_name, test)
suite.addTest(myClass(test))
test_name = "test_HSAILRunToTwoBreakpoints_%s"%testData[0]
test = test_genHSAILRunToTwoBreakpoints(testData)
setattr(TestWithDataFiles, test_name, test)
suite.addTest(myClass(test))
results = xmlrunner.XMLTestRunner(output="testlog").run(suite)
python ~/bin/generateTests.py --datafiles ~/.profile/home/bgriffin/.profile
Traceback (most recent call last):
File "/home/bgriffin/bin/generateTests.py", line 54, in <module>
suite.addTest(myClass(test))
File "/usr/lib/python2.7/unittest/suite.py", line 49, in addTest
raise TypeError("{} is not callable".format(repr(test)))
TypeError: None is not callable