forked from jmfee-usgs/geomag-algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Util_test.py
66 lines (54 loc) · 2.14 KB
/
Util_test.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
61
62
63
64
65
66
#! /usr/bin/env python
import os.path
import shutil
from nose.tools import assert_equals, assert_false
from geomagio import Util
from obspy.core import UTCDateTime
def test_get_file_for_url__throws_exception():
"""Util_test.test_get_file_for_url__throws_exception()
"""
# throws exception for non "file://" urls
try:
Util.get_file_from_url('http://someserver/path')
assert_false('expected exception')
except Exception:
pass
def test_get_file_for_url__parses_file_urls():
"""Util_test.test_get_file_for_url__parses_file_urls()
"""
# parses file urls
f = Util.get_file_from_url('file://./somefile')
assert_equals(f, './somefile')
def test_get_file_for_url__creates_directories():
"""Util_test.test_get_file_for_url__creates_directories()
"""
# creates directories if requested
if os.path.isdir('/tmp/_geomag_algorithms_test_'):
shutil.rmtree('/tmp/_geomag_algorithms_test_')
f = Util.get_file_from_url('file:///tmp/_geomag_algorithms_test_/somefile',
createParentDirectory=True)
if not os.path.isdir('/tmp/_geomag_algorithms_test_'):
assert_false('directory not created')
shutil.rmtree('/tmp/_geomag_algorithms_test_')
assert_equals(f, '/tmp/_geomag_algorithms_test_/somefile')
def test_get_interval__defaults():
"""Util_test.test_get_interval()
"""
starttime = UTCDateTime('2015-01-01T00:00:00Z')
endtime = UTCDateTime('2015-02-01T00:00:00Z')
intervals = Util.get_intervals(starttime, endtime)
assert_equals(len(intervals), 31)
def test_get_interval__custom_size():
"""Util_test.test_get_interval__custom_size()
"""
starttime = UTCDateTime('2015-01-01T00:00:00Z')
endtime = UTCDateTime('2015-01-02T00:00:00Z')
intervals = Util.get_intervals(starttime, endtime, size=3600)
assert_equals(len(intervals), 24)
def test_get_interval__trim():
"""Util_test.test_get_interval__trim()
"""
starttime = UTCDateTime('2015-01-01T01:00:00Z')
endtime = UTCDateTime('2015-01-02T00:00:00Z')
intervals = Util.get_intervals(starttime, endtime, trim=True)
assert_equals(intervals[0]['start'], starttime)