-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtest_utils.py
60 lines (46 loc) · 1.6 KB
/
test_utils.py
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
49
50
51
52
53
54
55
56
57
58
59
60
# SPDX-FileCopyrightText: Bernardo Chrispim Baron <[email protected]>
#
# SPDX-License-Identifier: MIT
"""Tests for the utilities to interact with Zenity and ActivityWatch."""
import pytest
from datetime import datetime
from aw_watcher_ask.utils import fix_id, is_valid_id, get_current_datetime
@pytest.mark.parametrize("valid_id", ["a.correct.id"])
def testis_valid_id(valid_id: str):
"""Tests recognizing a valid event_type id."""
assert is_valid_id(valid_id)
@pytest.mark.parametrize(
"invalid_id",
[
"a string with spaces",
"a_string_with_underscores",
"ã.string.wïth.nonáscii.çhars",
"AN.UPPERCASE.STRING",
],
)
def test_isnot_valid_id(invalid_id: str):
"""Tests recognizing forbidden event_type ids."""
assert not is_valid_id(invalid_id)
@pytest.mark.parametrize("valid_id", ["a.correct.id"])
def testfix_valid_id(valid_id: str):
"""Tests applying fix to an already correct event_type id."""
transformed_id = fix_id(valid_id)
assert is_valid_id(transformed_id)
assert valid_id == transformed_id
@pytest.mark.parametrize(
"invalid_id",
[
"a string with spaces",
"a_string_with_underscores",
"ã.string.wïth.nonáscii.çhars",
"AN.UPPERCASE.STRING",
],
)
def testfix_invalid_id(invalid_id: str):
"""Tests applying fix to event_type ids with incorrect ."""
assert is_valid_id(fix_id(invalid_id))
def test_get_current_datetime():
"""Returns the current UTC date and time."""
now = get_current_datetime()
assert isinstance(now, datetime)
assert now.tzname() == "UTC"