Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unrelated lints to tests #1063

Merged
merged 2 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions tests/testthat/test-class-comment.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ test_that("comments", {

expect_silent(write_comment(wb, 1, col = 6, row = 3, comment = c3))

expect_true(length(wb$comments) == 1)
expect_true(length(wb$comments[[1]]) == 3)
expect_length(wb$comments, 1)
expect_length(wb$comments[[1]], 3)

expect_silent(remove_comment(wb, 1, col = "B", row = 10))

expect_true(length(wb$comments) == 1)
expect_true(length(wb$comments[[1]]) == 2)
expect_length(wb$comments, 1)
expect_length(wb$comments[[1]], 2)

expect_silent(wb_save(wb, tmp))

Expand Down Expand Up @@ -376,6 +376,6 @@ test_that("background colors work", {

wb$add_comment(sheet = 1, dims = wb_dims(3, 6), comment = wb_comment(text = txt), color = wb_color("green"))

expect_true(grepl("fillcolor=\"#00FF00\"", wb$vml[[1]]))
expect_match(wb$vml[[1]], "fillcolor=\"#00FF00\"")

})
13 changes: 7 additions & 6 deletions tests/testthat/test-class-workbook.R
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,8 @@ test_that("clone worksheet", {
wb <- wb_load(fl)
wb$clone_worksheet(2, "Clone 1")

expect_true(grepl("test", wb$charts$chart[2]))
expect_true(grepl("'Clone 1'", wb$charts$chart[3]))
expect_match(wb$charts$chart[2], "test")
expect_match(wb$charts$chart[3], "'Clone 1'")
# wb$open()

# clone slicer ----------------------------------------------------------
Expand Down Expand Up @@ -622,9 +622,10 @@ test_that("add_drawing works", {
add_mschart(dims = "A1", graph = scatter_plot)$
add_mschart(dims = "F4:L20", graph = scatter_plot)

expect_true(grepl("absoluteAnchor", wb$drawings))
expect_true(grepl("oneCellAnchor", wb$drawings))
expect_true(grepl("twoCellAnchor", wb$drawings))
drawings <- as.character(wb$drawings)
expect_match(drawings, "absoluteAnchor")
expect_match(drawings, "oneCellAnchor")
expect_match(drawings, "twoCellAnchor")

})

Expand Down Expand Up @@ -653,7 +654,7 @@ test_that("add_chartsheet works", {

expect_equal(nrow(wb$charts), 1)

expect_true(grepl("A &amp; B", wb$charts$chart))
expect_match(wb$charts$chart, "A &amp; B")

expect_true(wb$is_chartsheet[[2]])

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-outlines.R
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ test_that("ungroup rows", {
ungroup_rows("Sheet 1", 1:4)

got <- wb$worksheets[[1]]$sheet_data$row_attr$outlineLevel
expect_true(all(got == ""))
expect_setequal(got, "")

})

Expand Down
12 changes: 6 additions & 6 deletions tests/testthat/test-page_setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ test_that("Page setup", {
expect_equal(wb$worksheets[[1]]$pageSetup, wb$worksheets[[2]]$pageSetup)

v <- gsub(" ", "", wb$worksheets[[1]]$pageSetup, fixed = TRUE)
expect_true(grepl('paperSize="1"', v))
expect_true(grepl('orientation="landscape"', v))
expect_true(grepl('fitToWidth="1"', v))
expect_true(grepl('fitToHeight="1"', v))
expect_match(v, 'paperSize="1"')
expect_match(v, 'orientation="landscape"')
expect_match(v, 'fitToWidth="1"')
expect_match(v, 'fitToHeight="1"')

pr <- wb$worksheets[[1]]$sheetPr
expect_true(grepl('<outlinePr summaryBelow="1" summaryRight="1"/>', pr, fixed = TRUE))
expect_match(pr, '<outlinePr summaryBelow="1" summaryRight="1"/>', fixed = TRUE)

pr <- wb$worksheets[[3]]$sheetPr
expect_equal("<sheetPr><tabColor rgb=\"FF00FF00\"/></sheetPr>", pr)
Expand All @@ -41,7 +41,7 @@ test_that("Page setup", {
)

pr <- wb$worksheets[[3]]$sheetPr
expect_equal("<sheetPr/>", pr)
expect_equal(pr, "<sheetPr/>")

})

Expand Down
12 changes: 6 additions & 6 deletions tests/testthat/test-pugi_cpp.R
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,14 @@ test_that("xml_append_child", {
expect_equal(xml_node, "<a><b><c>a&amp;b<d/></c></b><c>a&amp;b</c></a>")

# check that pointer is valid
expect_true(inherits(xml_append_child1(read_xml(xml_node), xml_child, pointer = TRUE), "pugi_xml"))
expect_true(inherits(xml_append_child1(read_xml(xml_node), xml_child, pointer = TRUE), "pugi_xml"))
expect_s3_class(xml_append_child1(read_xml(xml_node), xml_child, pointer = TRUE), "pugi_xml")
expect_s3_class(xml_append_child1(read_xml(xml_node), xml_child, pointer = TRUE), "pugi_xml")

expect_true(inherits(xml_append_child2(read_xml(xml_node), xml_child, level1 = "a", pointer = TRUE), "pugi_xml"))
expect_true(inherits(xml_append_child2(read_xml(xml_node), xml_child, level1 = "a", pointer = TRUE), "pugi_xml"))
expect_s3_class(xml_append_child2(read_xml(xml_node), xml_child, level1 = "a", pointer = TRUE), "pugi_xml")
expect_s3_class(xml_append_child2(read_xml(xml_node), xml_child, level1 = "a", pointer = TRUE), "pugi_xml")

expect_true(inherits(xml_append_child3(read_xml(xml_node), xml_child, level1 = "a", level2 = "b", pointer = TRUE), "pugi_xml"))
expect_true(inherits(xml_append_child3(read_xml(xml_node), xml_child, level1 = "a", level2 = "b", pointer = TRUE), "pugi_xml"))
expect_s3_class(xml_append_child3(read_xml(xml_node), xml_child, level1 = "a", level2 = "b", pointer = TRUE), "pugi_xml")
expect_s3_class(xml_append_child3(read_xml(xml_node), xml_child, level1 = "a", level2 = "b", pointer = TRUE), "pugi_xml")

})

Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-pugixml.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test_that("read_xml", {
x <- read_xml("<a><b/></a>")
exp <- "<a>\n <b/>\n</a>"

expect_true(inherits(x, "pugi_xml"))
expect_s3_class(x, "pugi_xml")

xml <- "<a> </a>"
got <- read_xml(xml, whitespace = TRUE, pointer = FALSE)
Expand All @@ -40,7 +40,7 @@ test_that("read_xml", {

# a character
y <- read_xml("<a><b/></a>", pointer = FALSE)
expect_true(is.character(y))
expect_type(y, "character")

# Errors if the import was unsuccessful
expect_error(z <- read_xml("<a><b/>"))
Expand Down
18 changes: 9 additions & 9 deletions tests/testthat/test-read_sources.R
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,10 @@

unzip(temp, exdir = xlsx_unzip)
overrides <- xml_node(read_xml(paste0(xlsx_unzip, "/[Content_Types].xml"), pointer = FALSE), "Types", "Override")
expect_match(overrides, "chartshapes", all = FALSE)

unlink(xlsx_unzip, recursive = TRUE)

expect_true(any(grepl("chartshapes", overrides)))

# check that the image is valid and was placed on the correct sheet and drawing
exp <- c(
Expand All @@ -185,7 +186,7 @@
rmsheet <- length(wb$worksheets) - 2
wb$remove_worksheet(rmsheet)

expect_false(any(grepl("drawing21.xml", unlist(wb$worksheets_rels))))
expect_no_match( unlist(wb$worksheets_rels), "drawing21.xml")

Check warning on line 189 in tests/testthat/test-read_sources.R

View workflow job for this annotation

GitHub Actions / lint

file=tests/testthat/test-read_sources.R,line=189,col=19,[spaces_inside_linter] Do not place spaces after parentheses.
olivroy marked this conversation as resolved.
Show resolved Hide resolved
expect_equal(wb$drawings[[21]], "")
expect_equal(wb$drawings_rels[[21]], "")

Expand Down Expand Up @@ -229,16 +230,15 @@
wb <- wb_load(testfile_path("connection.xlsx"))

expect_false(is.null(wb$customXml))
expect_equal(length(wb$customXml), 3)
expect_length(wb$customXml, 3)

wb$save(temp)

wb <- wb_load(temp)
expect_equal(length(wb$customXml), 3)

expect_true(grepl("customXml/_rels/item1.xml.rels", wb$customXml[1]))
expect_true(grepl("customXml/item1.xml", wb$customXml[2]))
expect_true(grepl("customXml/itemProps1.xml", wb$customXml[3]))
expect_length(wb$customXml, 3)
expect_match(wb$customXml[1], "customXml/_rels/item1.xml.rels")
expect_match(wb$customXml[2], "customXml/item1.xml")
expect_match(wb$customXml[3], "customXml/itemProps1.xml")

})

Expand Down Expand Up @@ -360,7 +360,7 @@
test_that("reading slicer for tables works", {
fl <- testfile_path("table_slicer.xlsx")
wb <- wb_load(fl)
expect_true(grepl("<x14:slicerCache r:id=\"rId100001\"/>", wb$workbook$extLst))
expect_match(wb$workbook$extLst, "<x14:slicerCache r:id=\"rId100001\"/>")
})

test_that("hyperlinks work", {
Expand Down
9 changes: 4 additions & 5 deletions tests/testthat/test-wb_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -448,10 +448,10 @@ test_that("improve non consecutive dims", {
exp <- dims_to_dataframe(dims, fill = TRUE)
exp <- unname(unlist(exp[exp != ""]))
got <- wb1$worksheets[[1]]$sheet_data$cc$r[wb1$worksheets[[1]]$sheet_data$cc$c_s != ""]
expect_true(all(exp %in% got))
expect_contains(got, exp)

got <- wb2$worksheets[[1]]$sheet_data$cc$r[wb2$worksheets[[1]]$sheet_data$cc$c_s != ""]
expect_true(all(exp %in% got))
expect_contains(got, exp)

### Test rowwise
# dims <- "D5:E5,I5:J5,C6:F6,H6:K6,B7:L9,C10:K10,D11:J11,E12:I12,F13:H13,G14"
Expand All @@ -473,9 +473,8 @@ test_that("improve non consecutive dims", {
exp <- dims_to_dataframe(dims, fill = TRUE)
exp <- unname(unlist(exp[exp != ""]))
got <- wb3$worksheets[[1]]$sheet_data$cc$r[wb3$worksheets[[1]]$sheet_data$cc$c_s != ""]
expect_true(all(exp %in% got))
expect_contains(got, exp)

got <- wb4$worksheets[[1]]$sheet_data$cc$r[wb4$worksheets[[1]]$sheet_data$cc$c_s != ""]
expect_true(all(exp %in% got))

expect_contains(got, exp)
})
2 changes: 1 addition & 1 deletion tests/testthat/test-wb_styles.R
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,6 @@ test_that("dims work", {
style = wb$styles_mgr$get_xf_id("xf")
)

expect_true(all(wb$worksheets[[1]]$sheet_data$cc$c_s == "1"))
expect_setequal(wb$worksheets[[1]]$sheet_data$cc$c_s, "1")

})
2 changes: 1 addition & 1 deletion tests/testthat/test-write.R
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ test_that("writing slicers works", {
expect_equal("x15:timelineCacheRefs", xml_node_name(wb$workbook$extLst, "extLst", "ext"))
expect_equal("timelines", xml_node_name(wb$timelines))
expect_equal("timelineCacheDefinition", xml_node_name(wb$timelineCaches))
expect_true(grepl("x15:timelineRefs", wb$worksheets[[2]]$extLst))
expect_match(wb$worksheets[[2]]$extLst, "x15:timelineRefs")

wb$add_slicer(df, slicer = "lttr", pivot_table = "pivot1")

Expand Down
Loading