finds and runs a file or directory of files as a unit test
| 286 | # PydevTestRunner |
| 287 | # ======================================================================================================================= |
| 288 | class PydevTestRunner(object): |
| 289 | """finds and runs a file or directory of files as a unit test""" |
| 290 | |
| 291 | __py_extensions = ["*.py", "*.pyw"] |
| 292 | __exclude_files = ["__init__.*"] |
| 293 | |
| 294 | # Just to check that only this attributes will be written to this file |
| 295 | __slots__ = [ |
| 296 | "verbosity", # Always used |
| 297 | "files_to_tests", # If this one is given, the ones below are not used |
| 298 | "files_or_dirs", # Files or directories received in the command line |
| 299 | "include_tests", # The filter used to collect the tests |
| 300 | "tests", # Strings with the tests to be run |
| 301 | "jobs", # Integer with the number of jobs that should be used to run the test cases |
| 302 | "split_jobs", # String with 'tests' or 'module' (how should the jobs be split) |
| 303 | "configuration", |
| 304 | "coverage", |
| 305 | ] |
| 306 | |
| 307 | def __init__(self, configuration): |
| 308 | self.verbosity = configuration.verbosity |
| 309 | |
| 310 | self.jobs = configuration.jobs |
| 311 | self.split_jobs = configuration.split_jobs |
| 312 | |
| 313 | files_to_tests = configuration.files_to_tests |
| 314 | if files_to_tests: |
| 315 | self.files_to_tests = files_to_tests |
| 316 | self.files_or_dirs = list(files_to_tests.keys()) |
| 317 | self.tests = None |
| 318 | else: |
| 319 | self.files_to_tests = {} |
| 320 | self.files_or_dirs = configuration.files_or_dirs |
| 321 | self.tests = configuration.tests |
| 322 | |
| 323 | self.configuration = configuration |
| 324 | self.__adjust_path() |
| 325 | |
| 326 | def __adjust_path(self): |
| 327 | """add the current file or directory to the python path""" |
| 328 | path_to_append = None |
| 329 | for n in range(len(self.files_or_dirs)): |
| 330 | dir_name = self.__unixify(self.files_or_dirs[n]) |
| 331 | if os.path.isdir(dir_name): |
| 332 | if not dir_name.endswith("/"): |
| 333 | self.files_or_dirs[n] = dir_name + "/" |
| 334 | path_to_append = os.path.normpath(dir_name) |
| 335 | elif os.path.isfile(dir_name): |
| 336 | path_to_append = os.path.dirname(dir_name) |
| 337 | else: |
| 338 | if not os.path.exists(dir_name): |
| 339 | block_line = "*" * 120 |
| 340 | sys.stderr.write("\n%s\n* PyDev test runner error: %s does not exist.\n%s\n" % (block_line, dir_name, block_line)) |
| 341 | return |
| 342 | msg = "unknown type. \n%s\nshould be file or a directory.\n" % (dir_name) |
| 343 | raise RuntimeError(msg) |
| 344 | if path_to_append is not None: |
| 345 | # Add it as the last one (so, first things are resolved against the default dirs and |