Skip to content

Commit bacf38f

Browse files
committed
new unit tests
1 parent 34cac8b commit bacf38f

File tree

7 files changed

+90
-2
lines changed

7 files changed

+90
-2
lines changed

tests/unit/date/test_mktz.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from pytest import raises
44

55
from arctic.date import mktz, TimezoneError
6-
from arctic.date._mktz import DEFAULT_TIME_ZONE_NAME
6+
from arctic.date._mktz import DEFAULT_TIME_ZONE_NAME, tzfile, TIME_ZONE_DATA_SOURCE
77

88

99
def test_mktz():
@@ -37,3 +37,9 @@ def test_mktz_fails_if_invalid_timezone():
3737
file_exists.return_value = False
3838
with raises(TimezoneError):
3939
mktz('junk')
40+
41+
42+
def test_tzfile_raises():
43+
t = tzfile(TIME_ZONE_DATA_SOURCE + DEFAULT_TIME_ZONE_NAME)
44+
with raises(ValueError):
45+
t._find_ttinfo(None)

tests/unit/date/test_util.py

+20
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,23 @@ def test_to_dt_dt_tz():
8686

8787
def test_to_dt_dt_tz_default():
8888
assert to_dt(dt(1970, 1, 1, tzinfo=mktz('UTC')), mktz('Europe/London')) == dt(1970, 1, 1, tzinfo=mktz('UTC'))
89+
90+
91+
def test_daterange_raises():
92+
with pytest.raises(ValueError):
93+
assert(DateRange(dt(2013, 1, 1), dt(2000, 1, 1)))
94+
95+
96+
def test_daterange_eq():
97+
dr = DateRange(dt(2013, 1, 1))
98+
assert((dr == None) == False)
99+
assert(dr == dr)
100+
101+
102+
def test_daterange_lt():
103+
dr = DateRange(dt(2013, 1, 1))
104+
dr2 = DateRange(2001, 1, 1)
105+
106+
assert(dr2 < dr)
107+
dr.start = None
108+
assert((dr2 < dr) == False)

tests/unit/store/test_version_item.py

+9
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,12 @@ def test_versioned_item_str_handles_none():
2424
metadata=None)
2525

2626
assert str(item)
27+
28+
29+
def test_versioned_item_metadata_dict():
30+
item = VersionedItem(symbol="test",
31+
library="test_lib",
32+
data=None,
33+
version=1.2,
34+
metadata=None)
35+
assert(item.metadata_dict() == {'symbol': 'test', 'library': 'test_lib', 'version': 1.2})

tests/unit/test_compression.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from mock import patch, Mock, sentinel, call
2-
from arctic._compression import compress, compress_array, decompress, decompress_array
2+
from arctic._compression import compress, compress_array, decompress, decompress_array, enable_parallel_lz4
33
import lz4
44

55

@@ -68,3 +68,13 @@ def test_compress_array_no_parallel():
6868
assert decompress_array(compress_array(a)) == a
6969
assert patch_lz4.compress.call_args_list == [call(x) for x in a]
7070
assert patch_lz4.decompress.call_args_list == [call(compress(x)) for x in a]
71+
72+
73+
def test_enable_parallel_lz4():
74+
enable_parallel_lz4(True)
75+
from arctic._compression import ENABLE_PARALLEL
76+
assert(ENABLE_PARALLEL == True)
77+
enable_parallel_lz4(False)
78+
from arctic._compression import ENABLE_PARALLEL
79+
assert(ENABLE_PARALLEL == False)
80+

tests/unit/test_fixtures.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import arctic.fixtures.arctic as fix
2+
from mock import Mock
3+
from arctic.arctic import Arctic
4+
5+
6+
def test_overlay_library_name():
7+
assert(fix.overlay_library_name() == 'test.OVERLAY')
8+
9+
10+
def test_overlay_library():
11+
a = Mock(Arctic, autospec=True)
12+
fix.overlay_library(a, "test")
13+
a.initialize_library.assert_called_with("test_RAW", "VersionStore", segment='year')
14+
15+
16+
def test_tickstore_lib():
17+
a = Mock(Arctic, autospec=True)
18+
fix.tickstore_lib(a, "test")
19+
a.initialize_library.assert_called_with('test', 'TickStoreV3')
20+
a.get_library.assert_called_with('test')

tests/unit/test_util.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from arctic._util import are_equals, enable_sharding
2+
from mock import MagicMock, ANY
3+
from arctic.arctic import Arctic
4+
5+
6+
def test_are_equals_not_df():
7+
assert(are_equals(1.0, 2.0) is False)
8+
assert(are_equals([1, 2, 3], [1,2,3]))
9+
assert(are_equals("Hello", "World") is False)
10+
11+
12+
def test_enable_sharding_hashed():
13+
m = MagicMock(Arctic, autospec=True)
14+
enable_sharding(m, "test", hashed=True)
15+
m._conn.admin.command.assert_called_with('shardCollection', ANY, key={'symbol': 'hashed'})

tests/unit/tickstore/test_toplevel.py

+8
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from arctic.tickstore.toplevel import TopLevelTickStore, TickStoreLibrary
1616
from dateutil.rrule import rrule, DAILY
1717
from arctic.tickstore.tickstore import TickStore
18+
from arctic.exceptions import UnhandledDtypeException
1819

1920

2021
def test_raise_exception_if_daterange_is_not_provided():
@@ -168,3 +169,10 @@ def test_read():
168169
sentinel.include_columns, include_images=sentinel.include_images),
169170
call(sentinel.symbol, tsl.date_range.intersection.return_value,
170171
sentinel.include_columns, include_images=sentinel.include_images)]
172+
173+
174+
def test_slice_raises():
175+
m = TopLevelTickStore(Mock())
176+
with pytest.raises(UnhandledDtypeException) as e:
177+
m._slice("abc", 1, 2)
178+
assert("Can't persist type" in str(e))

0 commit comments

Comments
 (0)