def test_get_syntribos_path(self): """Check that we get something reasonable from get_syntribos_path.""" root = ENV.get_syntribos_root() self.assertIsInstance(root, six.string_types) root_parent = os.path.abspath(os.path.join(root, "..")) path_parent = ENV.get_syntribos_path("..") self.assertEqual(root_parent, path_parent)
def test_get_syntribos_root(self): """Check that we get something reasonable from get_syntribos_root.""" root = ENV.get_syntribos_root() root_parent = os.path.abspath(os.path.join(root, "..")) self.assertIsInstance(root, six.string_types) self.assertIsNot("", root) self.assertIsNot("/", root) self.assertTrue(os.path.isdir(root_parent))
def run(cls, argv=sys.argv[1:], worker=False): """Method sets up logger and decides on Syntribos control flow This is the method where control flow of Syntribos is decided based on the commands entered. Depending upon commands such as ```list_tests``` or ```run``` the respective method is called. """ global result cls.worker = worker # If we are initializing, don't look for a default config file if "init" in sys.argv: cls.setup_config() else: cls.setup_config(use_file=True, argv=argv) try: if CONF.sub_command.name == "init": cli.print_symbol() ENV.initialize_syntribos_env() exit(0) elif CONF.sub_command.name == "list_tests": cli.print_symbol() cls.list_tests() exit(0) elif CONF.sub_command.name == "download": cli.print_symbol() ENV.download_wrapper() exit(0) elif CONF.sub_command.name == "root": print(ENV.get_syntribos_root()) exit(0) except AttributeError: print( _("Not able to run the requested sub command, please check " "the debug logs for more information, exiting...")) exit(1) if not ENV.is_syntribos_initialized(): print( _("Syntribos was not initialized. Please run the 'init'" " command or set it up manually. See the README for" " more information about the installation process.")) exit(1) cls.setup_runtime_env() decorator = unittest.runner._WritelnDecorator(cls.output) result = syntribos.result.IssueTestResult(decorator, True, verbosity=1) cls.start_time = time.time() if CONF.sub_command.name == "run": list_of_tests = list( cls.get_tests(CONF.test_types, CONF.excluded_types)) elif CONF.sub_command.name == "dry_run": dry_run_output = {"failures": [], "successes": []} list_of_tests = list(cls.get_tests(dry_run=True)) print(_("\nRunning Tests...:")) templates_dir = CONF.syntribos.templates if templates_dir is None: if cls.worker: raise Exception("No templates directory was found in the " "config file.") else: print( _("Attempting to download templates from {}").format( CONF.remote.templates_uri)) templates_path = remotes.get(CONF.remote.templates_uri) try: templates_dir = ContentType("r")(templates_path) except IOError: print( _("Not able to open `%s`; please verify path, " "exiting...") % templates_path) exit(1) print(_("\nPress Ctrl-C to pause or exit...\n")) meta_vars = None templates_dir = list(templates_dir) cls.meta_dir_dict = {} for file_path, file_content in templates_dir: if os.path.basename(file_path) == "meta.json": meta_path = os.path.dirname(file_path) try: cls.meta_dir_dict[meta_path] = json.loads(file_content) except json.decoder.JSONDecodeError: _full_path = os.path.abspath(file_path) print(syntribos.SEP) print( "\n" "*** The JSON parser raised an exception when parsing " "{}. Check that the file contains " "correctly formatted JSON data. ***\n".format( _full_path)) for file_path, req_str in templates_dir: if "meta.json" in file_path: continue meta_vars = cls.get_meta_vars(file_path) LOG = cls.get_logger(file_path) CONF.log_opt_values(LOG, logging.DEBUG) if not file_path.endswith(".template"): LOG.warning('file.....:%s (SKIPPED - not a .template file)', file_path) continue test_names = [t for (t, i) in list_of_tests] # noqa log_string = ''.join([ '\n{0}\nTEMPLATE FILE\n{0}\n'.format('-' * 12), 'file.......: {0}\n'.format(file_path), 'tests......: {0}\n'.format(test_names) ]) LOG.debug(log_string) print(syntribos.SEP) print("Template File...: {}".format(file_path)) print(syntribos.SEP) if CONF.sub_command.name == "run": cls.run_given_tests(list_of_tests, file_path, req_str, meta_vars) elif CONF.sub_command.name == "dry_run": cls.dry_run(list_of_tests, file_path, req_str, dry_run_output, meta_vars) if CONF.sub_command.name == "run": result.print_result(cls.start_time, cls.log_path) cls.result = result cleanup.delete_temps() elif CONF.sub_command.name == "dry_run": cls.dry_run_report(dry_run_output)
def run(cls, argv=sys.argv[1:], worker=False): """Method sets up logger and decides on Syntribos control flow This is the method where control flow of Syntribos is decided based on the commands entered. Depending upon commands such as ```list_tests``` or ```run``` the respective method is called. """ global result cls.worker = worker # If we are initializing, don't look for a default config file if "init" in sys.argv: cls.setup_config() else: cls.setup_config(use_file=True, argv=argv) try: if CONF.sub_command.name == "init": cli.print_symbol() ENV.initialize_syntribos_env() exit(0) elif CONF.sub_command.name == "list_tests": cli.print_symbol() cls.list_tests() exit(0) elif CONF.sub_command.name == "download": cli.print_symbol() ENV.download_wrapper() exit(0) elif CONF.sub_command.name == "root": print(ENV.get_syntribos_root()) exit(0) except AttributeError: print( _( "Not able to run the requested sub command, please check " "the debug logs for more information, exiting...")) exit(1) if not ENV.is_syntribos_initialized(): print(_("Syntribos was not initialized. Please run the 'init'" " command or set it up manually. See the README for" " more information about the installation process.")) exit(1) cls.setup_runtime_env() decorator = unittest.runner._WritelnDecorator(cls.output) result = syntribos.result.IssueTestResult(decorator, True, verbosity=1) cls.start_time = time.time() if CONF.sub_command.name == "run": list_of_tests = list( cls.get_tests(CONF.test_types, CONF.excluded_types)) elif CONF.sub_command.name == "dry_run": dry_run_output = {"failures": [], "successes": []} list_of_tests = list(cls.get_tests(dry_run=True)) print(_("\nRunning Tests...:")) templates_dir = CONF.syntribos.templates if templates_dir is None: if cls.worker: raise Exception("No templates directory was found in the " "config file.") else: print(_("Attempting to download templates from {}").format( CONF.remote.templates_uri)) templates_path = remotes.get(CONF.remote.templates_uri) try: templates_dir = ContentType("r")(templates_path) except IOError: print(_("Not able to open `%s`; please verify path, " "exiting...") % templates_path) exit(1) print(_("\nPress Ctrl-C to pause or exit...\n")) meta_vars = None templates_dir = list(templates_dir) cls.meta_dir_dict = {} for file_path, file_content in templates_dir: if os.path.basename(file_path) == "meta.json": meta_path = os.path.dirname(file_path) try: cls.meta_dir_dict[meta_path] = json.loads(file_content) except json.decoder.JSONDecodeError: _full_path = os.path.abspath(file_path) print(syntribos.SEP) print( "\n" "*** The JSON parser raised an exception when parsing " "{}. Check that the file contains " "correctly formatted JSON data. ***\n".format( _full_path) ) for file_path, req_str in templates_dir: if "meta.json" in file_path: continue meta_vars = cls.get_meta_vars(file_path) LOG = cls.get_logger(file_path) CONF.log_opt_values(LOG, logging.DEBUG) if not file_path.endswith(".template"): LOG.warning('file.....:%s (SKIPPED - not a .template file)', file_path) continue test_names = [t for (t, i) in list_of_tests] # noqa log_string = ''.join([ '\n{0}\nTEMPLATE FILE\n{0}\n'.format('-' * 12), 'file.......: {0}\n'.format(file_path), 'tests......: {0}\n'.format(test_names) ]) LOG.debug(log_string) print(syntribos.SEP) print("Template File...: {}".format(file_path)) print(syntribos.SEP) if CONF.sub_command.name == "run": cls.run_given_tests(list_of_tests, file_path, req_str, meta_vars) elif CONF.sub_command.name == "dry_run": cls.dry_run(list_of_tests, file_path, req_str, dry_run_output, meta_vars) if CONF.sub_command.name == "run": result.print_result(cls.start_time, cls.log_path) cls.result = result cleanup.delete_temps() elif CONF.sub_command.name == "dry_run": cls.dry_run_report(dry_run_output)
def test_create_env_dirs(self, makedirs): ENV.create_env_dirs(ENV.get_syntribos_root())