Skip to content

Commit

Permalink
Remove Mocking as dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
gwehrle committed Dec 5, 2024
1 parent b3a352d commit f42a54f
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 87 deletions.
2 changes: 0 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ version = "0.0.1"
[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
Mocking = "78c3b35d-d492-501b-9361-3d52fe80e533"
Preferences = "21216c6a-2e73-6563-6e65-726566657250"
URIs = "5c2747f8-b7ea-4ff2-ba2e-563bfd36b1d4"

[compat]
HTTP = "1.10.8"
Mocking = "0.8.1"
Preferences = "1.4.3"
URIs = "1.5.1"
julia = "1.10"
1 change: 0 additions & 1 deletion src/Overpass.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ using Preferences
using HTTP
using URIs
using Dates
using Mocking

export query, set_endpoint, status, turbo_url

Expand Down
3 changes: 1 addition & 2 deletions src/shortcuts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ Replaces `{{date}}` shortcuts in the query with the current or calculated date.
function replace_date_shortcuts(query::AbstractString)::AbstractString
if occursin(r"\{\{\s*?date"i, query)
# Get the current date and time
# @mock to fixate date in tests. Has no effect here.
current_date = @mock now(UTC)
current_date = now(UTC)

# Map string units to Dates.Period constructors
period_map = Dict(
Expand Down
Binary file modified test/HTTP/op-query-date-bbox.bson
Binary file not shown.
Binary file modified test/HTTP/op-query-date.bson
Binary file not shown.
Binary file modified test/HTTP/op-query-different-dates.bson
Binary file not shown.
13 changes: 1 addition & 12 deletions test/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

julia_version = "1.11.1"
manifest_format = "2.0"
project_hash = "871125b21c1da9a85e477dbc4b202688291e9123"
project_hash = "6fc63005bc4ee24c01f5dc27a601f5bdc6c5c3b3"

[[deps.Aqua]]
deps = ["Compat", "Pkg", "Test"]
Expand Down Expand Up @@ -84,11 +84,6 @@ git-tree-sha1 = "dcb08a0d93ec0b1cdc4af184b26b591e9695423a"
uuid = "460bff9d-24e4-43bc-9d9f-a8973cb893f4"
version = "0.1.10"

[[deps.ExprTools]]
git-tree-sha1 = "27415f162e6028e81c72b82ef756bf321213b6ec"
uuid = "e2ba6199-217a-4e67-a87a-7c52f15ade04"
version = "0.1.10"

[[deps.FileIO]]
deps = ["Pkg", "Requires", "UUIDs"]
git-tree-sha1 = "82d8afa92ecf4b52d78d869f038ebfb881267322"
Expand Down Expand Up @@ -222,12 +217,6 @@ version = "1.4.1"
uuid = "a63ad114-7e13-5084-954f-fe012c677804"
version = "1.11.0"

[[deps.Mocking]]
deps = ["Compat", "ExprTools"]
git-tree-sha1 = "2c140d60d7cb82badf06d8783800d0bcd1a7daa2"
uuid = "78c3b35d-d492-501b-9361-3d52fe80e533"
version = "0.8.1"

[[deps.MozillaCACerts_jll]]
uuid = "14a3606d-f60d-562e-9121-12d972cd8159"
version = "2023.12.12"
Expand Down
1 change: 0 additions & 1 deletion test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
BrokenRecord = "bdd55f5b-6e67-4da1-a080-6086e55655a0"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
Mocking = "78c3b35d-d492-501b-9361-3d52fe80e533"
Preferences = "21216c6a-2e73-6563-6e65-726566657250"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
132 changes: 63 additions & 69 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ using BrokenRecord: configure!, playback
using HTTP
using Preferences
using Dates
using Mocking

Mocking.activate()
fixed_date = @patch now(::Any) = DateTime(2024, 12, 1)

# Configure BrokenRecord
configure!(;
path = string(@__DIR__, "/HTTP/"), extension = "bson", ignore_headers = ["User-Agent"])
path = string(@__DIR__, "/HTTP/"),
extension = "bson",
ignore_headers = ["User-Agent"]
)

# Fixate now to fix date
Dates.now(::Type{UTC}) = DateTime(2024, 12, 1)

@testset "Overpass.jl" begin
@testset "query" begin
Expand Down Expand Up @@ -45,28 +48,22 @@ configure!(;
48.22702986850222, 16.364722959721423)),
"op-query-longquery") != ""

apply(fixed_date) do
@test playback(
() -> Overpass.query(
string(@__DIR__, "/queries/shortcut_date_and_bbox.overpassql"), bbox = (
48.224410300027, 16.36058699342046,
48.22702986850222, 16.364722959721423)),
"op-query-date-bbox") != ""
end
@test playback(
() -> Overpass.query(
string(@__DIR__, "/queries/shortcut_date_and_bbox.overpassql"), bbox = (
48.224410300027, 16.36058699342046,
48.22702986850222, 16.364722959721423)),
"op-query-date-bbox") != ""

apply(fixed_date) do
@test playback(
() -> Overpass.query(
string(@__DIR__, "/queries/shortcut_date.overpassql")),
"op-query-date") != ""
end
@test playback(
() -> Overpass.query(
string(@__DIR__, "/queries/shortcut_date.overpassql")),
"op-query-date") != ""

apply(fixed_date) do
@test playback(
() -> Overpass.query(
string(@__DIR__, "/queries/shortcut_different_dates.overpassql")),
"op-query-different-dates") != ""
end
@test playback(
() -> Overpass.query(
string(@__DIR__, "/queries/shortcut_different_dates.overpassql")),
"op-query-different-dates") != ""

@test_throws ErrorException playback(() -> Overpass.query("noddddddde;out;"),
"error")
Expand Down Expand Up @@ -217,52 +214,49 @@ configure!(;
end

@testset "date shortcut replacements" begin
apply(fixed_date) do
@test Overpass.replace_date_shortcuts("abc") == "abc"
@test DateTime(rstrip(Overpass.replace_shortcuts("{{ date }}"), 'Z'),
ISODateTimeFormat) == DateTime(2024, 12, 1)
@test DateTime(rstrip(Overpass.replace_shortcuts("{{date}}"), 'Z'),
ISODateTimeFormat) == DateTime(2024, 12, 1)
@test DateTime(rstrip(Overpass.replace_shortcuts("{{date:12years}}"), 'Z'),
ISODateTimeFormat) == DateTime(2012, 12, 1)
@test DateTime(rstrip(Overpass.replace_shortcuts("{{date:-1year}}"), 'Z'),
ISODateTimeFormat) == DateTime(2025, 12, 1)
@test DateTime(rstrip(Overpass.replace_shortcuts("{{date:12months}}"), 'Z'),
ISODateTimeFormat) == DateTime(2023, 12, 1)
@test DateTime(rstrip(Overpass.replace_shortcuts("{{date:-1month}}"), 'Z'),
ISODateTimeFormat) == DateTime(2025, 01, 1)
@test DateTime(
rstrip(Overpass.replace_shortcuts("{{ date : -3 months }}"), 'Z'),
ISODateTimeFormat) == DateTime(2025, 03, 1)
@test DateTime(rstrip(Overpass.replace_shortcuts("{{date:122 days}}"), 'Z'),
ISODateTimeFormat) == DateTime(2024, 08, 1)
@test DateTime(rstrip(Overpass.replace_shortcuts("{{date:-1day}}"), 'Z'),
ISODateTimeFormat) == DateTime(2024, 12, 2)
@test DateTime(rstrip(Overpass.replace_shortcuts("{{date:12weeks}}"), 'Z'),
ISODateTimeFormat) == DateTime(2024, 09, 08)
@test DateTime(rstrip(Overpass.replace_shortcuts("{{date:-1week}}"), 'Z'),
ISODateTimeFormat) == DateTime(2024, 12, 08)
@test DateTime(rstrip(Overpass.replace_shortcuts("{{date:+12hours}}"), 'Z'),
ISODateTimeFormat) == DateTime(2024, 11, 30, 12)
@test DateTime(rstrip(Overpass.replace_shortcuts("{{date:-1hour}}"), 'Z'),
ISODateTimeFormat) == DateTime(2024, 12, 1, 1)
@test DateTime(rstrip(Overpass.replace_shortcuts("{{DATE:12MINUTES}}"), 'Z'),
ISODateTimeFormat) == DateTime(2024, 11, 30, 23, 48)
@test DateTime(rstrip(Overpass.replace_shortcuts("{{date:-1minute}}"), 'Z'),
ISODateTimeFormat) == DateTime(2024, 12, 01, 0, 1)
@test DateTime(rstrip(Overpass.replace_shortcuts("{{date:12seconds}}"), 'Z'),
ISODateTimeFormat) == DateTime(2024, 11, 30, 23, 59, 48)
@test DateTime(rstrip(Overpass.replace_shortcuts("{{date:-1second}}"), 'Z'),
ISODateTimeFormat) == DateTime(2024, 12, 01, 0, 0, 1)
end

#multiple date shortcuts
multiple_date_shortcuts = DateTime.(rstrip.(
split(Overpass.replace_shortcuts("{{date:-10second}}#{{date:+10second}}"), "#"),
'Z'))
@test multiple_date_shortcuts[1] - multiple_date_shortcuts[2] == Millisecond(20000)
@test Overpass.replace_date_shortcuts("abc") == "abc"
@test DateTime(rstrip(Overpass.replace_shortcuts("{{ date }}"), 'Z'),
ISODateTimeFormat) == now(UTC)
@test DateTime(rstrip(Overpass.replace_shortcuts("{{date}}"), 'Z'),
ISODateTimeFormat) == now(UTC)
@test DateTime(rstrip(Overpass.replace_shortcuts("{{date:12years}}"), 'Z'),
ISODateTimeFormat) == now(UTC) - Year(12)
@test DateTime(rstrip(Overpass.replace_shortcuts("{{date:-1year}}"), 'Z'),
ISODateTimeFormat) == now(UTC) + Year(1)
@test DateTime(rstrip(Overpass.replace_shortcuts("{{date:12months}}"), 'Z'),
ISODateTimeFormat) == now(UTC) - Month(12)
@test DateTime(rstrip(Overpass.replace_shortcuts("{{date:-1month}}"), 'Z'),
ISODateTimeFormat) == now(UTC) + Month(1)
@test DateTime(rstrip(Overpass.replace_shortcuts("{{ date : -3 months }}"), 'Z'),
ISODateTimeFormat) == now(UTC) + Month(3)
@test DateTime(rstrip(Overpass.replace_shortcuts("{{date:122 days}}"), 'Z'),
ISODateTimeFormat) == now(UTC) - Day(122)
@test DateTime(rstrip(Overpass.replace_shortcuts("{{date:-1day}}"), 'Z'),
ISODateTimeFormat) == now(UTC) + Day(1)
@test DateTime(rstrip(Overpass.replace_shortcuts("{{date:12weeks}}"), 'Z'),
ISODateTimeFormat) == now(UTC) - Week(12)
@test DateTime(rstrip(Overpass.replace_shortcuts("{{date:-1week}}"), 'Z'),
ISODateTimeFormat) == now(UTC) + Week(1)
@test DateTime(rstrip(Overpass.replace_shortcuts("{{date:+12hours}}"), 'Z'),
ISODateTimeFormat) == now(UTC) - Hour(12)
@test DateTime(rstrip(Overpass.replace_shortcuts("{{date:-1hour}}"), 'Z'),
ISODateTimeFormat) == now(UTC) + Hour(1)
@test DateTime(rstrip(Overpass.replace_shortcuts("{{DATE:12MINUTES}}"), 'Z'),
ISODateTimeFormat) == now(UTC) - Minute(12)
@test DateTime(rstrip(Overpass.replace_shortcuts("{{date:-1minute}}"), 'Z'),
ISODateTimeFormat) == now(UTC) + Minute(1)
@test DateTime(rstrip(Overpass.replace_shortcuts("{{date:12seconds}}"), 'Z'),
ISODateTimeFormat) == now(UTC) - Second(12)
@test DateTime(rstrip(Overpass.replace_shortcuts("{{date:-1second}}"), 'Z'),
ISODateTimeFormat) == now(UTC) + Second(1)
end

#multiple date shortcuts
multiple_date_shortcuts = DateTime.(rstrip.(
split(Overpass.replace_shortcuts("{{date:-10second}}#{{date:+10second}}"), "#"),
'Z'))
@test multiple_date_shortcuts[1] - multiple_date_shortcuts[2] == Millisecond(20000)

@testset "check_remaining_shortcuts" begin
@test_throws MissingException Overpass.replace_shortcuts("{{bbox}}")
@test_throws MissingException Overpass.replace_shortcuts("{{center}}")
Expand Down

0 comments on commit f42a54f

Please sign in to comment.