git://git.onelab.eu
/
tests.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
834a68e
)
load tests from tests directory instead of modules
author
Tony Mack
<tmack@cs.princeton.edu>
Thu, 24 Jan 2008 18:16:51 +0000
(18:16 +0000)
committer
Tony Mack
<tmack@cs.princeton.edu>
Thu, 24 Jan 2008 18:16:51 +0000
(18:16 +0000)
qaapi/qa/QAAPI.py
patch
|
blob
|
history
diff --git
a/qaapi/qa/QAAPI.py
b/qaapi/qa/QAAPI.py
index
056d7a5
..
8a11236
100644
(file)
--- a/
qaapi/qa/QAAPI.py
+++ b/
qaapi/qa/QAAPI.py
@@
-1,12
+1,12
@@
import sys, os
import traceback
import sys, os
import traceback
-import
qa.module
s
-from
qa.
Config import Config
-from
qa.logger import log
+import
test
s
+from Config import Config
+from
logger import log
class QAAPI:
class QAAPI:
-
modules_path = os.path.realpath(qa.module
s.__path__[0])
+
tests_path = os.path.realpath(test
s.__path__[0])
methods = []
methods = []
@@
-14,20
+14,21
@@
class QAAPI:
if config is None: self.config = Config()
else: self.config = Config(config)
if config is None: self.config = Config()
else: self.config = Config(config)
-
module_files = self.module_files(self.module
s_path)
+
test_files = self.test_files(self.test
s_path)
callables = set()
# determine what is callable
callables = set()
# determine what is callable
- for file in module_files:
- callables.update(self.callables(file))
+ for file in test_files:
+ tests = self.callables(file)
+ tests = filter(lambda t: t.test_name not in ['Test'], tests)
+ callables.update(tests)
# Add methods to self and global environemt
# Add methods to self and global environemt
- for method in callables:
- if logging: method = log(method, method.
mod
_name)
+ for method in callables:
+ if logging: method = log(method, method.
test
_name)
elif hasattr(self.config, 'log') and self.config.log:
elif hasattr(self.config, 'log') and self.config.log:
- method = log(method, method.mod_name)
-
+ method = log(method, method.test_name)
class Dummy: pass
class Dummy: pass
- paths = method.
mod
_name.split(".")
+ paths = method.
test
_name.split(".")
if len(paths) > 1:
first = paths.pop(0)
if len(paths) > 1:
first = paths.pop(0)
@@
-45,60
+46,60
@@
class QAAPI:
if not hasattr(obj, path):
if path == paths[-1]:
setattr(obj, path, method)
if not hasattr(obj, path):
if path == paths[-1]:
setattr(obj, path, method)
- globals[method.
mod
_name]=obj
+ globals[method.
test
_name]=obj
else:
setattr(obj, path, Dummy())
obj = getattr(obj, path)
else:
if globals is not None:
else:
setattr(obj, path, Dummy())
obj = getattr(obj, path)
else:
if globals is not None:
- globals[method.
mod_name] = method
+ globals[method.
test_name] = method
- def
module_files(self, module
_dir):
+ def
test_files(self, tests
_dir):
"""
Build a list of files
"""
"""
Build a list of files
"""
- # Load files from
module
s direcotry
+ # Load files from
test
s direcotry
real_files = lambda name: not name.startswith('__init__') \
and name.endswith('.py')
remove_ext = lambda name: name.split(".py")[0]
real_files = lambda name: not name.startswith('__init__') \
and name.endswith('.py')
remove_ext = lambda name: name.split(".py")[0]
- iterator = os.walk(
module
_dir)
+ iterator = os.walk(
tests
_dir)
(root, basenames, files) = iterator.next()
(root, basenames, files) = iterator.next()
-
module
_base = ""
-
module
_files = []
-
module_files.extend([method
_base+file for file in map(remove_ext, filter(real_files, files))])
-
-
# recurse through directory
+
test
_base = ""
+
test
_files = []
+
test_files.extend([test
_base+file for file in map(remove_ext, filter(real_files, files))])
+
+ # recurse through directory
for (root, dirs, files) in iterator:
parts = root.split(os.sep)
for basename in basenames:
if basename in parts:
for (root, dirs, files) in iterator:
parts = root.split(os.sep)
for basename in basenames:
if basename in parts:
-
module
_base = ".".join(parts[parts.index(basename):])+"."
+
test
_base = ".".join(parts[parts.index(basename):])+"."
files = filter(real_files, files)
files = map(remove_ext, files)
files = filter(real_files, files)
files = map(remove_ext, files)
- module_files.extend([module_base+file for file in files])
-
- return module_files
+ test_files.extend([test_base+file for file in files])
+ return list(set(test_files))
- def callables(self,
module
_file):
+ def callables(self,
test
_file):
"""
Return a new instance of the specified method.
"""
# Get new instance of method
"""
Return a new instance of the specified method.
"""
# Get new instance of method
- parts =
module
_file.split(".")
+ parts =
test
_file.split(".")
# add every part except for the last to name (filename)
# add every part except for the last to name (filename)
- module_dir = "qa.modules."
- module_basename = ".".join(parts[:-1])
- module_path = module_dir + module_file
+ tests_dir = "tests."
+ test_basename = ".".join(parts[:-1])
+ if test_basename: test_basename += '.'
+ test_path = tests_dir + test_file
try:
try:
-
module = __import__(module_path, globals(), locals(), module
_path)
+
test = __import__(test_path, globals(), locals(), test
_path)
callables = []
callables = []
- for attribute in dir(
module
):
- attr = getattr(
module
, attribute)
+ for attribute in dir(
test
):
+ attr = getattr(
test
, attribute)
if callable(attr) and hasattr(attr, 'status'):
if callable(attr) and hasattr(attr, 'status'):
- setattr(attr, '
mod_name', module_basename+"."
+attribute)
+ setattr(attr, '
test_name', test_basename
+attribute)
callables.append(attr(self.config))
return callables
except ImportError, AttributeError:
callables.append(attr(self.config))
return callables
except ImportError, AttributeError: