Skip to content

Instantly share code, notes, and snippets.

@Sighery
Last active March 5, 2020 11:23
Show Gist options
  • Select an option

  • Save Sighery/348889a6c783a280f332654b507fc0d4 to your computer and use it in GitHub Desktop.

Select an option

Save Sighery/348889a6c783a280f332654b507fc0d4 to your computer and use it in GitHub Desktop.
Test collections.abc deprecation warning in datetoken
venv/
__pycache__/
freezegun
datetoken==0.4.0
pytest
import argparse
import unittest
from datetime import datetime
from freezegun import freeze_time
import datetoken.exceptions
import datetoken.utils
def parse_relative_time(input_token: str) -> str:
try:
parsed = datetoken.utils.token_to_date(input_token)
except datetoken.exceptions.InvalidTokenException:
raise Exception("test")
return parsed.strftime("%y-%m-%dT%H:%M:%S")
class ParseRelativeTimeTestCase(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.time_format = "%y-%m-%dT%H:%M:%S"
@freeze_time()
def test_valid_token_returns_expected_datetime_string(self):
input_token = "now"
expected = datetime.utcnow().strftime(self.time_format)
self.assertEqual(parse_relative_time(input_token), expected)
def test_invalid_token_raises_exception(self):
input_token = "test-token"
with self.assertRaises(Exception):
parse_relative_time(input_token)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment