From cadb40c1c58baf8f60da5e470b56d39865575943 Mon Sep 17 00:00:00 2001 From: Matt Kerlogue Date: Sat, 6 May 2023 01:34:01 +0100 Subject: [PATCH] Add unzip tests --- tests/testthat/test-ods_xml.R | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/testthat/test-ods_xml.R b/tests/testthat/test-ods_xml.R index 4a93e75..1bfb41b 100644 --- a/tests/testthat/test-ods_xml.R +++ b/tests/testthat/test-ods_xml.R @@ -1,6 +1,28 @@ example_file <- system.file("extdata", "basic_example.ods", package = "tidyods") excel_file <- system.file("extdata", "basic_example_excel.ods", package = "tidyods") +test_that("File handling errors", { + expect_error(unzip_ods_xml("nonexistent.csv"), regexp = "does not exist") + expect_error(unzip_ods_xml("test-ods_xml.R"), regexp = "does not have a valid extension") +}) + +test_that("File parsing", { + expect_vector(unzip_ods_xml(example_file), ptype = character(), size = 1) + expect_match(unzip_ods_xml(example_file), "content.xml$") +}) + +test_that("XMl extraction fails", { + + mockery::stub( + extract_ods_xml, + "unzip_ods_xml", + "path/not/here.xml" + ) + + expect_error(extract_ods_xml(example_file), "Error in unzip procedure") + +}) + test_that("XML extraction (LibreOffice)", { expect_silent(example_ods <- extract_ods_xml(example_file)) expect_type(example_ods, "list")