Debian Codegraph @

tests/cli/test_utils.py

raw
1 import argparse
2 from datetime import datetime
3
4 import pytest
5
6 from censys.cli.utils import valid_datetime_type
7 from tests.utils import CensysTestCase
8
9
10 class CensysCliUtilsTest(CensysTestCase):
11 @pytest.mark.parametrize(
12 ("string", "expected"),
13 [
14 ("2021-05-20", datetime(2021, 5, 20)),
15 ("2021-05-20 12:00", datetime(2021, 5, 20, 12, 00)),
16 ],
17 )
18 def test_valid_datetime(self, string, expected):
19 # Actual call
20 actual = valid_datetime_type(string)
21 # Assertions
22 assert actual == expected
23
24 @pytest.mark.parametrize(
25 "string",
26 [
27 "2021/05/20",
28 "2021/05/20 12:00",
29 ],
30 )
31 def test_invalid_datetime(self, string):
32 # Actuall call/error raising
33 with pytest.raises(argparse.ArgumentTypeError):
34 valid_datetime_type(string)