def get_query_from_yaml(config_path): """Creates a Query object from a yaml file found in config_path. The Query object is created from the configuration found in the yaml file. Filters objects are created from the yaml file aswell and are attached to the Query. :param config_path: Path to the configuration yaml file. :return: A Query object along with the filters in the file, if found. """ try: with open(config_path) as config_file: yaml_contents = yaml.load(config_file) except IOError: sys.exit('The config.yaml path you provided, `{0}`, does not ' 'lead to an existing file.'.format(config_path)) yaml_config = yaml_contents['query_config'] yaml_filters = yaml_contents['filters'] qc = QueryConfig.from_yaml(yaml_config) filters = [Filter.from_yaml(yaml_filter) for yaml_filter in yaml_filters] query = Query.from_config(qc) query.attach_filters(filters) return query
def get_query_from_args(args): """Creates a Query object from the CLI arguments. Filter objects are created from the CLI argument and attached to the Query object. :param args: CLI arguments :return: A Query object along with the created filters, if found. """ qc = QueryConfig.from_args(args) filters = get_filters_from_args(args) query = Query.from_config(qc) query.attach_filters(filters) return query
def test_attach_filters(self): sorted_filters = [NameFilter(1, None), IssueFilter(2, None, None, None) ] unsorted_filters = [IssueFilter(2, None, None, None), NameFilter(1, None) ] q = Query(None) q.attach_filters(sorted_filters) self.assertEqual(q.filters, sorted_filters) q.filters = [] q.attach_filters(unsorted_filters) self.assertEqual(q.filters, sorted_filters)
def test_get_query_class(self): self.assertEqual(Query.get_query_class('branch'), BranchQuery)