forked from singer-io/singer-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_utils.py
More file actions
35 lines (28 loc) · 987 Bytes
/
test_utils.py
File metadata and controls
35 lines (28 loc) · 987 Bytes
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
import unittest
from datetime import datetime as dt
import pytz
import logging
import singer.utils as u
class TestFormat(unittest.TestCase):
def test_small_years(self):
self.assertEqual(u.strftime(dt(90, 1, 1, tzinfo=pytz.UTC)),
"0090-01-01T00:00:00.000000Z")
def test_round_trip(self):
now = dt.utcnow().replace(tzinfo=pytz.UTC)
dtime = u.strftime(now)
pdtime = u.strptime_to_utc(dtime)
fdtime = u.strftime(pdtime)
self.assertEqual(dtime, fdtime)
class TestHandleException(unittest.TestCase):
def setUp(self):
self.logger = logging.getLogger(__name__)
def test_successful_fn(self):
@u.handle_top_exception(self.logger)
def foo():
return 3
self.assertEqual(foo(), 3)
def test_exception_fn(self):
@u.handle_top_exception(self.logger)
def foo():
raise RuntimeError("foo")
self.assertRaises(RuntimeError, foo)