def test_text_selector(self): import json _selector = compose_selectors( select_all_descendants, make_filter(lambda x: x.is_named("set-cookie")), select_text) b = nodify("root", json.load(open("../sample3.json"))) self.assertEqual(_selector(b), query("**/set-cookie/text()", b))
def test_text_selector(self): import json _selector = compose_selectors( select_all_descendants, make_filter(lambda x: x.is_named("set-cookie")), select_text ) b = nodify("root", json.load(open("../sample3.json"))) self.assertEqual(_selector(b), query("**/set-cookie/text()", b))
def test_simple_compose(self): _selector = compose_selectors( select_all_descendants, select_children(lambda x: x.is_named("a")), select_all_children) self.assertEqual( _selector(self.tree).as_json(), query("**/a/*", self.tree).as_json(), )
def test_simple_compose(self): _selector = compose_selectors( select_all_descendants, select_children(lambda x: x.is_named("a")), select_all_children ) self.assertEqual( _selector(self.tree).as_json(), query("**/a/*", self.tree).as_json(), )
def _build_payload(query=None, title=None, authors=None, dates=None, affiliation=None, affiliation_pos=None, fl=None, acknowledgements=None, facet=None, sort="date", order="desc", start=0, rows=20, database="astronomy or physics", property=None, **kwargs): """Builds a dictionary payload for NASA's ADS based on the input criteria.""" q = parser.query(query, title, authors) # Check inputs start, rows = parser.rows(start, rows, max_rows=API_MAX_ROWS) sort, order = parser.ordering(sort, order) # Filters pubdate_filter = parser.dates(dates) affiliation_filter = parser.affiliation(affiliation, affiliation_pos) acknowledgements_filter = parser.acknowledgements(acknowledgements) # You shouldn't ever use 'property' since it's special, but we're being consistent with ADS properties_filter = parser.properties(property) q += " ".join([ each for each in (pubdate_filter, affiliation_filter, acknowledgements_filter, properties_filter) if each is not None ]) payload = { "q": q, "dev_key": DEV_KEY, "sort": "{sort} {order}".format(sort=sort.upper(), order=order), "start": start, "fmt": "json", "rows": rows, } additional_payload = { "fl": fl, "filter": parser.database(database), "facet": facet } payload.update(additional_payload) return payload
def _build_payload(query=None, title=None, authors=None, dates=None, affiliation=None, affiliation_pos=None, fl=None, acknowledgements=None, facet=None, sort="date", order="desc", start=0, rows=20, database="astronomy or physics", property=None, **kwargs): """Builds a dictionary payload for NASA's ADS based on the input criteria.""" q = parser.query(query, title, authors) # Check inputs start, rows = parser.rows(start, rows, max_rows=API_MAX_ROWS) sort, order = parser.ordering(sort, order) # Filters pubdate_filter = parser.dates(dates) affiliation_filter = parser.affiliation(affiliation, affiliation_pos) acknowledgements_filter = parser.acknowledgements(acknowledgements) # You shouldn't ever use 'property' since it's special, but we're being consistent with ADS properties_filter = parser.properties(property) q += " ".join([each for each in (pubdate_filter, affiliation_filter, acknowledgements_filter, properties_filter) if each is not None]) payload = { "q": q, "dev_key": DEV_KEY, "sort": "{sort} {order}".format(sort=sort.upper(), order=order), "start": start, "fmt": "json", "rows": rows, } additional_payload = { "fl": fl, "filter": parser.database(database), "facet": facet } payload.update(additional_payload) return payload
def _build_payload(query=None, authors=None, dates=None, affiliation=None, affiliation_pos=None, filter=None, fl=None, acknowledgements=None, facet=None, sort="date", order="desc", start=0, rows=20): """Builds a dictionary payload for NASA's ADS based on the input criteria.""" q = parser.query(query, authors) # Check inputs start, rows = parser.rows(start, rows, max_rows=API_MAX_ROWS) sort, order = parser.ordering(sort, order) # Filters pubdate_filter = parser.dates(dates) affiliation_filter = parser.affiliation(affiliation, affiliation_pos) acknowledgements_filter = parser.acknowledgements(acknowledgements) filters = (pubdate_filter, affiliation_filter, acknowledgements_filter) for query_filter in filters: if query_filter is not None: q += query_filter payload = { "q": q, "dev_key": DEV_KEY, "sort": "{sort} {order}".format(sort=sort.upper(), order=order), "start": start, "fmt": "json", "rows": rows, } additional_payload = { "fl": fl, "filter": filter, "facet": facet } payload.update(additional_payload) return payload
def test_conditional(self): nodes = query("**[z]", self.tree).as_json() self.assertEquals(len(nodes), 4) nodes = query("*[a]", self.tree) self.assertEquals(len(nodes.as_json()), 2)
def test_simple_paths(self): for path in self.test_paths: print [path, query(path, self.tree).as_json()]
def test_simple_paths(self): for path in self.test_paths: print[path, query(path, self.tree).as_json()]