Skip to content

Commit

Permalink
add some tests for date_format, time_format and datetime_format
Browse files Browse the repository at this point in the history
  • Loading branch information
etiennebacher committed Oct 17, 2023
1 parent dee4402 commit 460bf3b
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
46 changes: 46 additions & 0 deletions tests/testthat/_snaps/csv.md
Original file line number Diff line number Diff line change
Expand Up @@ -383,3 +383,49 @@
"""foo""",1,"a"
"bar",2,"b"

# write_csv: date_format works

Code
cat(readLines(path), sep = "\n")
Output
date
2020
2021
2022
2023

---

Code
cat(readLines(path), sep = "\n")
Output
date
01/01/2020
01/01/2021
01/01/2022
01/01/2023

# write_csv: datetime_format works

Code
cat(readLines(path), sep = "\n")
Output
date
00h00m - 01/01/2020
06h00m - 01/01/2020
12h00m - 01/01/2020
18h00m - 01/01/2020
00h00m - 02/01/2020

# write_csv: time_format works

Code
cat(readLines(path), sep = "\n")
Output
date
2023-10-16T22:00:00.000000
2023-10-16T22:15:00.000000
2023-10-16T22:30:00.000000
2023-10-16T22:45:00.000000
2023-10-16T23:00:00.000000

41 changes: 41 additions & 0 deletions tests/testthat/test-csv.R
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,44 @@ patrick::with_parameters_test_that(
},
quote_style = c("necessary", "always", "non_numeric")
)

test_that("write_csv: date_format works", {
dat <- pl$DataFrame(
date = pl$date_range(
as.Date("2020-01-01"),
as.Date("2023-01-02"),
interval = "1y",
eager = TRUE
)
)
dat$write_csv(temp_out, date_format = "%Y")
expect_snapshot_file(temp_out)
dat$write_csv(temp_out, date_format = "%d/%m/%Y")
expect_snapshot_file(temp_out)
})

test_that("write_csv: datetime_format works", {
dat <- pl$DataFrame(
date = pl$date_range(
as.Date("2020-01-01"),
as.Date("2020-01-02"),
interval = "6h",
eager = TRUE
)
)
dat$write_csv(temp_out, datetime_format = "%Hh%Mm - %d/%m/%Y")
expect_snapshot_file(temp_out)
})

test_that("write_csv: time_format works", {
dat <- pl$DataFrame(
date = pl$date_range(
strptime("00:00:00", format = "%H:%M:%S"),
strptime("01:00:00", format = "%H:%M:%S"),
interval = "15m",
eager = TRUE
)
)
dat$write_csv(temp_out, time_format = "%Hh%Mm%%Ss")
expect_snapshot_file(temp_out)
})

0 comments on commit 460bf3b

Please sign in to comment.