Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lvaudor committed Oct 20, 2023
1 parent cdbe9ba commit e81232d
Show file tree
Hide file tree
Showing 27 changed files with 624 additions and 616 deletions.
2 changes: 2 additions & 0 deletions tests/testthat/_snaps/build_parts.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
spq_mutate(coords = wdt::P625(city), .within_distance = list(center = c(long = 4.84,
lat = 45.76), radius = 5))
Output
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?city (COALESCE(?city_labell,'') AS ?city_label) ?coords
WHERE {
Expand Down
37 changes: 0 additions & 37 deletions tests/testthat/_snaps/send_sparql.md

This file was deleted.

5 changes: 2 additions & 3 deletions tests/testthat/_snaps/sparql-protection.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

Code
spq(1)
Condition
Error in `c_character()`:
! Character input expected
Error <rlang_error>
Character input expected

4 changes: 2 additions & 2 deletions tests/testthat/_snaps/spq_add.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Code
spq_init() %>% spq_add(spq("?software p:P348/pq:P577 ?date"))
Output
PREFIX p: <http://www.wikidata.org/prop/>
SELECT ?date ?software
WHERE {
Expand All @@ -17,7 +17,7 @@
Code
spq_init() %>% spq_add(spq("?software pq:P577 ?date."))
Output
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
SELECT ?date ?software
WHERE {
Expand Down
9 changes: 6 additions & 3 deletions tests/testthat/_snaps/spq_assemble.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
spq_summarise(subject_label_concat = str_c(subject_label, sep = "; ")) %>%
spq_head(10)
Output
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?film (GROUP_CONCAT(?subject_label;SEPARATOR="; ") AS ?subject_label_concat)
WHERE {
Expand All @@ -30,6 +32,8 @@
spq_init() %>% spq_add("?item wdt:P31 wd:Q13442814") %>% spq_label(item) %>%
spq_filter(str_detect(str_to_lower(item_label), "wikidata")) %>% spq_head(n = 5)
Output
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?item (COALESCE(?item_labell,'') AS ?item_label)
WHERE {
Expand All @@ -50,9 +54,8 @@

Code
spq_init() %>% spq_filter(lang(itemTitleLOOKTYPO) == "en") %>% spq_assemble()
Condition
Error in `spq_assemble()`:
! Can't filter on undefined variables: ?itemTitleLOOKTYPO
Error <rlang_error>
Can't filter on undefined variables: ?itemTitleLOOKTYPO
i You haven't mentioned them in any triple, VALUES, mutate.

# spq_assemble() called from printing isn't strict
Expand Down
25 changes: 10 additions & 15 deletions tests/testthat/_snaps/spq_control_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,37 @@

Code
spq_control_request(timeout = "ahahah")
Condition
Error in `spq_control_request()`:
! Must provide an integer as `timeout`.
Error <rlang_error>
Must provide an integer as `timeout`.
i You provided a "character".

---

Code
spq_control_request(max_tries = "ahahah")
Condition
Error in `spq_control_request()`:
! Must provide an integer as `max_tries`.
Error <rlang_error>
Must provide an integer as `max_tries`.
i You provided a "character".

---

Code
spq_control_request(max_seconds = "ahahah")
Condition
Error in `spq_control_request()`:
! Must provide an integer as `max_seconds`.
Error <rlang_error>
Must provide an integer as `max_seconds`.
i You provided a "character".

---

Code
spq_control_request(request_type = "ahahah")
Condition
Error in `spq_control_request()`:
! `request_type` must be one of "url" or "body-form", not "ahahah".
Error <rlang_error>
`request_type` must be one of "url" or "body-form", not "ahahah".

---

Code
spq_control_request(user_agent = 42)
Condition
Error in `spq_control_request()`:
! Must provide a character as `user_agent`.
Error <rlang_error>
Must provide a character as `user_agent`.

4 changes: 4 additions & 0 deletions tests/testthat/_snaps/spq_filter.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"CONTAINS(LCASE(?itemTitle),'wikidata')")) %>% spq_filter(spq(
"LANG(?itemTitle)='en'"))
Output
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?item ?itemTitle
WHERE {
Expand All @@ -24,6 +26,8 @@
"?item rdfs:label ?itemTitle") %>% spq_filter(str_detect(str_to_lower(
itemTitle), "wikidata")) %>% spq_filter(lang(itemTitle) == "en")
Output
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?item ?itemTitle
WHERE {
Expand Down
7 changes: 4 additions & 3 deletions tests/testthat/_snaps/spq_init.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
narrative_location = wdt::P840(film)) %>% spq_label(film, narrative_location) %>%
spq_count(narrative_location_label, sort = TRUE, name = "n_films")
Output
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?narrative_location_label (COUNT(*) AS ?n_films)
WHERE {
Expand All @@ -31,7 +33,6 @@

Code
spq_init(request_control = list(max_tries = 1L))
Condition
Error in `spq_init()`:
! `request_control` must be created by `spq_control_request()`.
Error <rlang_error>
`request_control` must be created by `spq_control_request()`.

19 changes: 19 additions & 0 deletions tests/testthat/_snaps/spq_label.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
spq_add("?node ps:P39 wd:Q30185") %>% spq_add("?node pq:P642 ?place") %>%
spq_label(mayor, place, .languages = "en$")
Output
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?mayor (COALESCE(?mayor_labell,'') AS ?mayor_label) ?node ?place (COALESCE(?place_labell,'') AS ?place_label) ?species
WHERE {
Expand Down Expand Up @@ -37,6 +42,11 @@
spq_add("?node ps:P39 wd:Q30185") %>% spq_add("?node pq:P642 ?place") %>%
spq_label(mayor, place, .languages = c("fr", "en"))
Output
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?mayor (COALESCE(?mayor_labell,'') AS ?mayor_label) (lang(?mayor_labell) AS ?mayor_label_lang) ?node ?place (COALESCE(?place_labell,'') AS ?place_label) (lang(?place_labell) AS ?place_label_lang) ?species
WHERE {
Expand Down Expand Up @@ -92,6 +102,11 @@
spq_add("?node ps:P39 wd:Q30185") %>% spq_add("?node pq:P642 ?place") %>%
spq_label(mayor, place, .languages = "en$", .overwrite = TRUE)
Output
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?node ?species (COALESCE(?mayor_labell,'') AS ?mayor) (COALESCE(?place_labell,'') AS ?place)
WHERE {
Expand Down Expand Up @@ -146,6 +161,8 @@
spq_add("?film wdt:P577 ?date") %>% spq_label(film, loc, subject) %>%
spq_head(10)
Output
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?coords ?date ?film (COALESCE(?film_labell,'') AS ?film_label) ?image ?loc (COALESCE(?loc_labell,'') AS ?loc_label) ?subject (COALESCE(?subject_labell,'') AS ?subject_label)
WHERE {
Expand Down Expand Up @@ -188,6 +205,8 @@
spq_add("?film wdt:P577 ?date") %>% spq_label(film, loc, subject, .required = TRUE) %>%
spq_head(10)
Output
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?coords ?date ?film (COALESCE(?film_labell,'') AS ?film_label) ?image ?loc (COALESCE(?loc_labell,'') AS ?loc_label) ?subject (COALESCE(?subject_labell,'') AS ?subject_label)
WHERE {
Expand Down
3 changes: 1 addition & 2 deletions tests/testthat/_snaps/spq_language.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

Code
spq_init() %>% spq_language("en")
Condition
Warning:
Warning <lifecycle_warning_deprecated>
`spq_language()` was deprecated in glitter 0.2.0.
i Please use `spq_label()` instead.
i See the `.languages` argument
Expand Down
7 changes: 6 additions & 1 deletion tests/testthat/_snaps/spq_mutate.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
spq_init() %>% spq_mutate(statement = wdt::P1843(wd::Q331676)) %>% spq_mutate(
lang = lang(statement))
Output
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
SELECT ?statement (lang(?statement) AS ?lang)
WHERE {
Expand All @@ -20,6 +21,8 @@
spq_add("?film wdt:P577 ?date") %>% spq_mutate(date = year(date)) %>%
spq_head(10)
Output
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?film (COALESCE(?film_labell,'') AS ?film_label) (YEAR(?date0) AS ?date)
WHERE {
Expand All @@ -43,6 +46,8 @@
spq_add("?film wdt:P577 ?date") %>% spq_mutate(date = year(date)) %>%
spq_mutate(date = date - 2000)
Output
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?film (COALESCE(?film_labell,'') AS ?film_label) (?date0-2000 AS ?date)
WHERE {
Expand Down
3 changes: 3 additions & 0 deletions tests/testthat/_snaps/spq_offset.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
"?item wikibase:sitelinks ?linkcount") %>% spq_arrange(desc(linkcount)) %>%
spq_head(42) %>% spq_offset(11)
Output
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?item (COALESCE(?item_labell,'') AS ?item_label) ?linkcount
WHERE {
Expand Down
10 changes: 4 additions & 6 deletions tests/testthat/_snaps/spq_select.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,8 @@
spq_init() %>% spq_add("?station wdt:P16 wd:Q1552") %>% spq_add(
"?station wdt:P31 wd:Q928830") %>% spq_add("?station wdt:P625 ?coords") %>%
spq_select(station_label, blop)
Condition
Error in `check_variables_present()`:
! Can't use `spq_select()` on absent variables: ?station_label, ?blop.
Error <rlang_error>
Can't use `spq_select()` on absent variables: ?station_label, ?blop.
i Did you forget a call to `spq_add()`, `spq_mutate()` or `spq_label()`?

---
Expand All @@ -169,8 +168,7 @@
spq_init() %>% spq_add("?station wdt:P16 wd:Q1552") %>% spq_add(
"?station wdt:P31 wd:Q928830") %>% spq_add("?station wdt:P625 ?coords") %>%
spq_label(station) %>% spq_select(station_label, blop)
Condition
Error in `check_variables_present()`:
! Can't use `spq_select()` on absent variables: ?blop.
Error <rlang_error>
Can't use `spq_select()` on absent variables: ?blop.
i Did you forget a call to `spq_add()`, `spq_mutate()` or `spq_label()`?

20 changes: 16 additions & 4 deletions tests/testthat/_snaps/spq_summarise.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
spq_label(area) %>% spq_add("?area wdt:P527 ?item") %>% spq_group_by(area,
area_label) %>% spq_summarise(total_folkm = sum(folkm_ngd))
Output
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?area ?area_label (SUM(?folkm_ngd) AS ?total_folkm)
WHERE {
Expand All @@ -31,6 +33,8 @@
spq_init() %>% spq_add("?film wdt:P31 wd:Q11424") %>% spq_add(
"?film wdt:P840 ?loc") %>% spq_label(film, loc) %>% spq_summarise(n_films = n())
Output
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT (COUNT(*) AS ?n_films)
WHERE {
Expand Down Expand Up @@ -58,6 +62,8 @@
"?film wdt:P840 ?loc") %>% spq_label(film, loc) %>% spq_group_by(loc) %>%
spq_summarise(n_films = n())
Output
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?loc (COUNT(*) AS ?n_films)
WHERE {
Expand Down Expand Up @@ -87,7 +93,8 @@
year) %>% spq_summarise(n_films = n(), one_film = sample(film)) %>% spq_head(
10)
Output
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
SELECT ?year (COUNT(*) AS ?n_films) (SAMPLE(?film) AS ?one_film)
WHERE {
Expand All @@ -106,7 +113,8 @@
spq_init() %>% spq_add("?film wdt:P31 wd:Q11424") %>% spq_add(
"?film wdt:P840 ?loc") %>% spq_summarise(n_films = n())
Output
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
SELECT (COUNT(*) AS ?n_films)
WHERE {
Expand All @@ -124,6 +132,8 @@
spq_label(area) %>% spq_add("?area wdt:P527 ?item") %>% spq_group_by(area,
area_label) %>% spq_summarise(folkm_ngd = sum(folkm_ngd))
Output
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?area ?area_label (SUM(?folkm_ngd0) AS ?folkm_ngd)
WHERE {
Expand Down Expand Up @@ -151,7 +161,8 @@
year = year(date)) %>% spq_mutate(year = min(year)) %>% spq_group_by(loc,
year) %>% spq_summarize(n_films = n())
Output
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
SELECT ?loc ?year (COUNT(*) AS ?n_films)
WHERE {
Expand All @@ -172,7 +183,8 @@
"?film wdt:P577 ?date") %>% spq_mutate(year = year(date)) %>% spq_group_by(
filmLabel, loc) %>% spq_summarise(year = min(year))
Output
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
SELECT (MIN(?year0) AS ?year)
WHERE {
Expand Down
Loading

0 comments on commit e81232d

Please sign in to comment.