Esempio n. 1
0
    def build_suite(self, loaded_module):
        """
        loads the found tests and builds the test suite
        """
        tag_list = []
        attrs = {}
        loader = unittest.TestLoader()
        suite = OpenCafeUnittestTestSuite()
        loaded = LoadedTestClass(loaded_module)

        if self.tags:
            tag_list, attrs, token = self._parse_tags(self.tags)

        if (hasattr(loaded_module, "load_tests")
                and not self.supress
                and self.method_regex == "test_*"
                and self.tags is None):
            load_tests = getattr(loaded_module, "load_tests")
            suite.addTests(load_tests(loader, None, None))
            return suite

        for class_ in loaded.get_instances():
            for method_name in dir(class_):
                load_test_flag = False

                if fnmatch(method_name, self.method_regex):
                    if not self.tags:
                        load_test_flag = True
                    else:
                        load_test_flag = self._check_method(
                            class_, method_name, tag_list, attrs, token)
                    if load_test_flag:
                        suite.addTest(class_(method_name))
        return suite
def load_tests(loader, standard_tests, pattern):
    suite = OpenCafeUnittestTestSuite()
    tests = [
        "test_format_volume_on_server", "test_mount_volume_on_server",
        "test_verify_volume_writability", "test_verify_volume_readability",
        "test_unmount_used_volume", "test_detach_unmounted_volume"
    ]
    for t in tests:
        suite.addTest(VolumeIntegrationSmokeTests(t))
    return suite
Esempio n. 3
0
def load_tests(loader, standard_tests, pattern):
    suite = OpenCafeUnittestTestSuite()
    suite.addTest(VolumeAttachmentsAPISmoke("test_attach_volume_to_server"))
    suite.addTest(
        VolumeAttachmentsAPISmoke("test_list_server_volume_attachments"))
    suite.addTest(
        VolumeAttachmentsAPISmoke("test_get_volume_attachment_details"))
    suite.addTest(VolumeAttachmentsAPISmoke("test_volume_attachment_delete"))

    return suite
Esempio n. 4
0
    def generate_suite(self):
        """
        creates a single unittest test suite
        """
        master_suite = OpenCafeUnittestTestSuite()
        modules = self.get_modules()

        for modname in modules:
            suite = self.build_suite(modname)
            if suite:
                master_suite.addTests(suite)
        return master_suite
Esempio n. 5
0
 def load_file(self):
     """Load a file generated by --dry_run"""
     suites = []
     for key, value in self.file_.items():
         suite = OpenCafeUnittestTestSuite()
         module, class_ = key.rsplit(".", 1)
         module = importlib.import_module(module)
         class_ = getattr(module, class_)
         for test in value:
             suite.addTest(class_(test))
         suites.append(suite)
     return suites
def load_tests(loader, standard_tests, pattern):
    suite = OpenCafeUnittestTestSuite()
    tests = [
        "test_format_volume_on_server",
        "test_mount_volume_on_server",
        "test_verify_volume_writability",
        "test_verify_volume_readability",
        "test_unmount_used_volume",
        "test_detach_unmounted_volume"]
    for t in tests:
        suite.addTest(VolumeIntegrationSmokeTests(t))
    return suite
Esempio n. 7
0
 def load_file(self):
     """Load a file generated by --dry_run"""
     suites = []
     for key, value in self.file_.items():
         suite = OpenCafeUnittestTestSuite()
         module, class_ = key.rsplit(".", 1)
         module = importlib.import_module(module)
         class_ = getattr(module, class_)
         for test in value:
             suite.addTest(class_(test))
         suites.append(suite)
     return suites
Esempio n. 8
0
    def generate_suite(self):
        """
        creates a single unittest test suite
        """
        master_suite = OpenCafeUnittestTestSuite()
        modules = self.get_modules()

        for modname in modules:
            suite = self.build_suite(modname)
            if suite:
                master_suite.addTests(suite)
        return master_suite
Esempio n. 9
0
def load_tests(loader, standard_tests, pattern):
    suite = OpenCafeUnittestTestSuite()
    suite.addTest(VolumeAttachmentsAPISmoke("test_attach_volume_to_server"))
    suite.addTest(
        VolumeAttachmentsAPISmoke("test_list_server_volume_attachments"))
    suite.addTest(
        VolumeAttachmentsAPISmoke("test_get_volume_attachment_details"))
    suite.addTest(VolumeAttachmentsAPISmoke("test_volume_attachment_delete"))

    return suite
Esempio n. 10
0
 def get_suites(self):
     """Creates the suites for testing given the options in init"""
     test_suites = self.load_file()
     for class_ in self._get_classes(self._get_modules()):
         suite = OpenCafeUnittestTestSuite()
         for test in self._get_tests(class_):
             suite.addTest(class_(test))
         if suite._tests:
             test_suites.append(suite)
     if self.dry_run:
         for suite in test_suites:
             for test in suite:
                 print(test)
         exit(0)
     for suite in test_suites:
         suite.cafe_uuid = uuid.uuid4()
     return test_suites
Esempio n. 11
0
 def get_suites(self):
     """Creates the suites for testing given the options in init"""
     test_suites = self.load_file()
     for class_ in self._get_classes(self._get_modules()):
         suite = OpenCafeUnittestTestSuite()
         for test in self._get_tests(class_):
             suite.addTest(class_(test))
         if suite._tests:
             test_suites.append(suite)
     if self.dry_run:
         for suite in test_suites:
             for test in suite:
                 print(test)
         exit(0)
     for suite in test_suites:
         suite.cafe_uuid = uuid.uuid4()
     return test_suites
Esempio n. 12
0
    def run(self):
        """
        loops through all the packages, modules, and methods sent in from
        the command line and runs them
        """
        master_suite = OpenCafeUnittestTestSuite()
        parallel_test_list = []
        test_count = 0

        builder = SuiteBuilder(self.cl_args, self.test_env.test_repo_package)
        test_runner = self.get_runner(self.cl_args)

        if self.cl_args.parallel:
            parallel_test_list = builder.generate_suite_list()
            test_count = len(parallel_test_list)
            if self.cl_args.dry_run:
                for suite in parallel_test_list:
                    for test in suite:
                        print(test)
                exit(0)
            exit_code = self.run_parallel(
                parallel_test_list,
                test_runner,
                result_type=self.cl_args.result,
                results_path=self.cl_args.result_directory)
        else:
            master_suite = builder.generate_suite()
            test_count = master_suite.countTestCases()
            if self.cl_args.dry_run:
                for test in master_suite:
                    print(test)
                exit(0)
            exit_code = self.run_serialized(
                master_suite,
                test_runner,
                result_type=self.cl_args.result,
                results_path=self.cl_args.result_directory)
        """
        Exit with a non-zero exit code if no tests where run, so that
        external monitoring programs (like Jenkins) can tell
        something is up
        """
        if test_count <= 0:
            exit_code = 1
        exit(exit_code)
Esempio n. 13
0
    def run(self):
        """
        loops through all the packages, modules, and methods sent in from
        the command line and runs them
        """
        master_suite = OpenCafeUnittestTestSuite()
        parallel_test_list = []
        test_count = 0

        builder = SuiteBuilder(self.cl_args, self.test_env.test_repo_package)
        test_runner = self.get_runner(self.cl_args)

        if self.cl_args.parallel:
            parallel_test_list = builder.generate_suite_list()
            test_count = len(parallel_test_list)
            if self.cl_args.dry_run:
                for suite in parallel_test_list:
                    for test in suite:
                        print(test)
                exit(0)
            exit_code = self.run_parallel(
                parallel_test_list, test_runner,
                result_type=self.cl_args.result,
                results_path=self.cl_args.result_directory)
        else:
            master_suite = builder.generate_suite()
            test_count = master_suite.countTestCases()
            if self.cl_args.dry_run:
                for test in master_suite:
                    print(test)
                exit(0)
            exit_code = self.run_serialized(
                master_suite, test_runner, result_type=self.cl_args.result,
                results_path=self.cl_args.result_directory)

        """
        Exit with a non-zero exit code if no tests where run, so that
        external monitoring programs (like Jenkins) can tell
        something is up
        """
        if test_count <= 0:
            exit_code = 1
        exit(exit_code)
Esempio n. 14
0
    def build_suite(self, module_path):
        """
        loads the found tests and builds the test suite
        """
        tag_list = []
        attrs = {}
        loader = unittest.TestLoader()
        suite = OpenCafeUnittestTestSuite()
        try:
            loaded_module = import_module(module_path)
        except Exception as e:
            sys.stderr.write("{0}\n".format("=" * 70))
            sys.stderr.write(
                "Failed to load module '{0}'\n".format(module_path, e))
            sys.stderr.write("{0}\n".format("-" * 70))
            print_exc(file=sys.stderr)
            sys.stderr.write("{0}\n".format("-" * 70))
            return

        if self.tags:
            tag_list, attrs, token = self._parse_tags(self.tags)

        if (hasattr(loaded_module, "load_tests")
                and not self.supress
                and not self.method_regex
                and self.tags is None):
            load_tests = getattr(loaded_module, "load_tests")
            suite.addTests(load_tests(loader, None, None))
            return suite

        for class_ in self.get_classes(loaded_module):
            for method_name in dir(class_):
                if (method_name.startswith("test_") and
                    search(self.method_regex, method_name) and
                    (not self.tags or self._check_method(
                        class_, method_name, tag_list, attrs, token))):
                    suite.addTest(class_(method_name))
        return suite
Esempio n. 15
0
    def run(self):
        """
        loops through all the packages, modules, and methods sent in from
        the command line and runs them
        """
        master_suite = OpenCafeUnittestTestSuite()
        parallel_test_list = []

        builder = SuiteBuilder(self.cl_args, self.test_env.test_repo_package)
        test_runner = self.get_runner(self.cl_args)

        if self.cl_args.parallel:
            parallel_test_list = builder.generate_suite_list()
            if self.cl_args.dry_run:
                for suite in parallel_test_list:
                    for test in suite:
                        print test
                exit(0)
            exit_code = self.run_parallel(
                parallel_test_list,
                test_runner,
                result_type=self.cl_args.result,
                results_path=self.cl_args.result_directory)
            exit(exit_code)
        else:
            master_suite = builder.generate_suite()
            if self.cl_args.dry_run:
                for test in master_suite:
                    print test
                exit(0)
            exit_code = self.run_serialized(
                master_suite,
                test_runner,
                result_type=self.cl_args.result,
                results_path=self.cl_args.result_directory)

            exit(exit_code)
Esempio n. 16
0
    def build_suite(self, module_path):
        """
        loads the found tests and builds the test suite
        """
        tag_list = []
        attrs = {}
        loader = unittest.TestLoader()
        suite = OpenCafeUnittestTestSuite()
        try:
            loaded_module = import_module(module_path)
        except Exception as e:
            sys.stderr.write("{0}\n".format("=" * 70))
            sys.stderr.write("Failed to load module '{0}'\n".format(
                module_path, e))
            sys.stderr.write("{0}\n".format("-" * 70))
            print_exc(file=sys.stderr)
            sys.stderr.write("{0}\n".format("-" * 70))
            return

        if self.tags:
            tag_list, attrs, token = self._parse_tags(self.tags)

        if (hasattr(loaded_module, "load_tests") and not self.supress
                and not self.method_regex and self.tags is None):
            load_tests = getattr(loaded_module, "load_tests")
            suite.addTests(load_tests(loader, None, None))
            return suite

        for class_ in self.get_classes(loaded_module):
            for method_name in dir(class_):
                if (method_name.startswith("test_")
                        and search(self.method_regex, method_name)
                        and (not self.tags or self._check_method(
                            class_, method_name, tag_list, attrs, token))):
                    suite.addTest(class_(method_name))
        return suite