Skip to content

Commit

Permalink
tests: test deepl_update()
Browse files Browse the repository at this point in the history
  • Loading branch information
maelle committed Dec 7, 2023
1 parent 9e1dc62 commit 5939721
Show file tree
Hide file tree
Showing 7 changed files with 367 additions and 0 deletions.
157 changes: 157 additions & 0 deletions tests/testthat/fixtures/git1/api/languages-298d87.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
[
{
"language": "BG",
"name": "Bulgarian",
"supports_formality": false
},
{
"language": "CS",
"name": "Czech",
"supports_formality": false
},
{
"language": "DA",
"name": "Danish",
"supports_formality": false
},
{
"language": "DE",
"name": "German",
"supports_formality": true
},
{
"language": "EL",
"name": "Greek",
"supports_formality": false
},
{
"language": "EN-GB",
"name": "English (British)",
"supports_formality": false
},
{
"language": "EN-US",
"name": "English (American)",
"supports_formality": false
},
{
"language": "ES",
"name": "Spanish",
"supports_formality": true
},
{
"language": "ET",
"name": "Estonian",
"supports_formality": false
},
{
"language": "FI",
"name": "Finnish",
"supports_formality": false
},
{
"language": "FR",
"name": "French",
"supports_formality": true
},
{
"language": "HU",
"name": "Hungarian",
"supports_formality": false
},
{
"language": "ID",
"name": "Indonesian",
"supports_formality": false
},
{
"language": "IT",
"name": "Italian",
"supports_formality": true
},
{
"language": "JA",
"name": "Japanese",
"supports_formality": true
},
{
"language": "KO",
"name": "Korean",
"supports_formality": false
},
{
"language": "LT",
"name": "Lithuanian",
"supports_formality": false
},
{
"language": "LV",
"name": "Latvian",
"supports_formality": false
},
{
"language": "NB",
"name": "Norwegian",
"supports_formality": false
},
{
"language": "NL",
"name": "Dutch",
"supports_formality": true
},
{
"language": "PL",
"name": "Polish",
"supports_formality": true
},
{
"language": "PT-BR",
"name": "Portuguese (Brazilian)",
"supports_formality": true
},
{
"language": "PT-PT",
"name": "Portuguese (European)",
"supports_formality": true
},
{
"language": "RO",
"name": "Romanian",
"supports_formality": false
},
{
"language": "RU",
"name": "Russian",
"supports_formality": true
},
{
"language": "SK",
"name": "Slovak",
"supports_formality": false
},
{
"language": "SL",
"name": "Slovenian",
"supports_formality": false
},
{
"language": "SV",
"name": "Swedish",
"supports_formality": false
},
{
"language": "TR",
"name": "Turkish",
"supports_formality": false
},
{
"language": "UK",
"name": "Ukrainian",
"supports_formality": false
},
{
"language": "ZH",
"name": "Chinese (simplified)",
"supports_formality": false
}
]
118 changes: 118 additions & 0 deletions tests/testthat/fixtures/git1/api/languages-d70faa.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
[
{
"language": "BG",
"name": "Bulgarian"
},
{
"language": "CS",
"name": "Czech"
},
{
"language": "DA",
"name": "Danish"
},
{
"language": "DE",
"name": "German"
},
{
"language": "EL",
"name": "Greek"
},
{
"language": "EN",
"name": "English"
},
{
"language": "ES",
"name": "Spanish"
},
{
"language": "ET",
"name": "Estonian"
},
{
"language": "FI",
"name": "Finnish"
},
{
"language": "FR",
"name": "French"
},
{
"language": "HU",
"name": "Hungarian"
},
{
"language": "ID",
"name": "Indonesian"
},
{
"language": "IT",
"name": "Italian"
},
{
"language": "JA",
"name": "Japanese"
},
{
"language": "KO",
"name": "Korean"
},
{
"language": "LT",
"name": "Lithuanian"
},
{
"language": "LV",
"name": "Latvian"
},
{
"language": "NB",
"name": "Norwegian"
},
{
"language": "NL",
"name": "Dutch"
},
{
"language": "PL",
"name": "Polish"
},
{
"language": "PT",
"name": "Portuguese"
},
{
"language": "RO",
"name": "Romanian"
},
{
"language": "RU",
"name": "Russian"
},
{
"language": "SK",
"name": "Slovak"
},
{
"language": "SL",
"name": "Slovenian"
},
{
"language": "SV",
"name": "Swedish"
},
{
"language": "TR",
"name": "Turkish"
},
{
"language": "UK",
"name": "Ukrainian"
},
{
"language": "ZH",
"name": "Chinese"
}
]
8 changes: 8 additions & 0 deletions tests/testthat/fixtures/git1/api/translate-dfd682-POST.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"translations": [
{
"detected_source_language": "EN",
"text": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE document SYSTEM \"CommonMark.dtd\">\n<document xmlns=\"http://commonmark.org/xml/1.0\">\n <heading level=\"1\">\n <text xml:space=\"preserve\">cabecera<\/text>\n <\/heading>\n <paragraph>\n <text xml:space=\"preserve\">esto es un texto<\/text>\n <\/paragraph>\n <heading level=\"2\">\n <text xml:space=\"preserve\">subtítulo<\/text>\n <\/heading>\n <paragraph>\n <text xml:space=\"preserve\">¡bonito!<\/text>\n <\/paragraph>\n<\/document>\n"
}
]
}
8 changes: 8 additions & 0 deletions tests/testthat/fixtures/git2/api/translate-996cd0-POST.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"translations": [
{
"detected_source_language": "EN",
"text": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE document SYSTEM \"CommonMark.dtd\">\n<document xmlns=\"http://commonmark.org/xml/1.0\">\n <heading level=\"1\">\n <text xml:space=\"preserve\">un título<\/text>\n <\/heading>\n<\/document>\n"
}
]
}
8 changes: 8 additions & 0 deletions tests/testthat/fixtures/git2/api/translate-d45a92-POST.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"translations": [
{
"detected_source_language": "EN",
"text": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE document SYSTEM \"CommonMark.dtd\">\n<document xmlns=\"http://commonmark.org/xml/1.0\">\n <paragraph>\n <text xml:space=\"preserve\">impresionante<\/text>\n <\/paragraph>\n<\/document>\n"
}
]
}
10 changes: 10 additions & 0 deletions tests/testthat/git1/api/languages-d70faa.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
structure(list(method = "GET", url = "api/languages?type=source",
status_code = 403L, headers = structure(list(date = "Tue, 05 Dec 2023 12:44:02 GMT",
`access-control-allow-origin` = "*", `strict-transport-security` = "max-age=63072000; includeSubDomains; preload",
`server-timing` = "l7_lb_tls;dur=117, l7_lb_idle;dur=0, l7_lb_receive;dur=0, l7_lb_total;dur=130",
`access-control-expose-headers` = "Server-Timing"), class = "httr2_headers"),
body = raw(0), request = structure(list(url = "https://api.deepl.com/v2/languages?type=source",
method = "GET", headers = structure(list(Authorization = "DeepL-Auth-Key lalala"), redact = character(0)),
body = NULL, fields = list(), options = list(), policies = list(
retry_max_tries = 3)), class = "httr2_request"),
cache = new.env(parent = emptyenv())), class = "httr2_response")
58 changes: 58 additions & 0 deletions tests/testthat/test-update.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
test_that("deepl_update() works", {

dir <- withr::local_tempdir()
file <- file.path(dir, "bla.md")
fs::file_create(file)
out_file <- file.path(dir, "bla.es.md")

brio::write_lines(
c("# header", "", "this is some text", "## subtitle", "", "nice!"),
file
)

with_mock_dir("git1", {
deepl_translate(
path = file,
out_path = out_file,
source_lang = "EN",
target_lang = "ES",
formality = "less",
yaml_fields = NULL
)
})

gert::git_init(dir)
gert::git_config_set("user.name", "Jane Doe", repo = dir)
gert::git_config_set("user.email", "[email protected]", repo = dir)
gert::git_add(c(fs::path_file(file), fs::path_file(out_file)), repo = dir)
gert::git_commit_all("First commit", repo = dir)

brio::write_lines(
c("# a title", "", "this is some text", "", "awesome", "", "## subtitle", ""),
file
)
gert::git_add(fs::path_file(file), repo = dir)
gert::git_commit("Second commit", repo = dir)

original_translation <- brio::read_lines(out_file)

with_mock_dir("git2", {
deepl_update(
path = file,
out_path = out_file,
source_lang = "EN",
target_lang = "ES",
formality = "less",
yaml_fields = NULL
)
})

new_translation <- brio::read_lines(out_file)
expect_true(
!all(new_translation %in% original_translation)
)
expect_true(
any(new_translation %in% original_translation)
)

})

0 comments on commit 5939721

Please sign in to comment.