forked from equinor/tagreader-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_utils.py
More file actions
48 lines (40 loc) · 1.79 KB
/
test_utils.py
File metadata and controls
48 lines (40 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import os
import datetime
import pytest
from pytz import timezone
from tagreader.utils import (
ensure_datetime_with_tz,
urljoin,
is_equinor
)
is_GITHUBACTION = "GITHUB_ACTION" in os.environ
is_AZUREPIPELINE = "TF_BUILD" in os.environ
def test_ensure_is_datetime():
assert ensure_datetime_with_tz("10. jan. 2018 13:45:15") == timezone(
"Europe/Oslo"
).localize(datetime.datetime(2018, 1, 10, 13, 45, 15))
assert ensure_datetime_with_tz("02.01.03 00:00:00") == timezone(
"Europe/Oslo"
).localize(datetime.datetime(2003, 1, 2, 0, 0, 0))
assert ensure_datetime_with_tz("02.01.03 00:00:00") == ensure_datetime_with_tz(
"2003-02-01 0:00:00am"
)
assert ensure_datetime_with_tz(
"02.01.03 00:00:00", "America/Sao_Paulo"
) == timezone("America/Sao_Paulo").localize(datetime.datetime(2003, 1, 2, 0, 0, 0))
assert ensure_datetime_with_tz("02.01.03 00:00:00", tz="Brazil/East") == timezone(
"Brazil/East"
).localize(datetime.datetime(2003, 1, 2, 0, 0, 0))
assert ensure_datetime_with_tz(
timezone("Brazil/East").localize(datetime.datetime(2003, 1, 2, 0, 0, 0)),
tz="Europe/Oslo",
) == timezone("Brazil/East").localize(datetime.datetime(2003, 1, 2, 0, 0, 0))
def test_urljoin():
assert urljoin("https://some.where/to", "go") == "https://some.where/to/go"
assert urljoin("https://some.where/to/", "go") == "https://some.where/to/go"
assert urljoin("https://some.where/to", "/go") == "https://some.where/to/go"
assert urljoin("https://some.where/to/", "/go") == "https://some.where/to/go"
assert urljoin("https://some.where/to", "go/") == "https://some.where/to/go/"
@pytest.mark.skipif(is_GITHUBACTION, reason="Only valid for Windows environments")
def test_equnor():
assert is_equinor() is True