Skip to content

Commit 4e89390

Browse files
Added tests to check that a date accessed was auto assigned on upload. working on #24
1 parent 98b8082 commit 4e89390

7 files changed

+109
-79
lines changed

snowexsql/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
"""Top-level package for snowexsql."""
22

33
__author__ = """Micah Johnson"""
4-
__email__ = '[email protected]'
54
__version__ = '0.1.0'

snowexsql/utilities.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,5 +154,5 @@ def get_file_creation_date(file):
154154
the system
155155
"""
156156

157-
result = datetime.datetime.fromtimestamp(getctime(file))
157+
result = datetime.datetime.fromtimestamp(getctime(file)).date()
158158
return result

tests/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
"""Unit test package for snowexsql."""
1+
""" Test package for snowexsql."""

tests/test_layers.py

+23-18
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import datetime
2-
from datetime import date, time
2+
from datetime import date
33

44
import numpy as np
5-
import pandas as pd
6-
import pytest
75
import pytz
86

97
from snowexsql.data import LayerData
@@ -63,20 +61,27 @@ class TestStratigraphyProfile(TableTestBase):
6361
dict(data_name='manual_wetness', attribute_to_count='value', expected_count=1),
6462
# Test only 3 hand hardness categories were used
6563
dict(data_name='hand_hardness', attribute_to_count='value', expected_count=3),
66-
# Test only 2 graint type categories were used
64+
# Test only 2 grain type categories were used
6765
dict(data_name='grain_type', attribute_to_count='value', expected_count=2),
6866
# Test only 2 grain_sizes were used
6967
dict(data_name='grain_size', attribute_to_count='value', expected_count=2),
7068

7169
]
7270
}
7371

72+
def test_date_accessed(self):
73+
"""
74+
Tests that the date accessed is auto assigned on upload
75+
"""
76+
result = self.session.query(LayerData.date_accessed).limit(1).all()
77+
assert type(result[0][0]) is date
78+
7479

7580
class TestDensityProfile(TableTestBase):
76-
'''
81+
"""
7782
Test that a density file is uploaded correctly including sample
7883
averaging for the main value.
79-
'''
84+
"""
8085

8186
args = ['density.csv']
8287
kwargs = {'timezone': 'MST'}
@@ -104,17 +109,17 @@ class TestDensityProfile(TableTestBase):
104109
}
105110

106111
def test_bottom_depth(self):
107-
'''
112+
"""
108113
Insure bottom depth info is not lost after standardizing it
109-
'''
114+
"""
110115
records = self.session.query(LayerData.bottom_depth).filter(LayerData.id <= 2).all()
111116
assert records[0][0] - records[1][0] == 10
112117

113118

114119
class TestLWCProfile(TableTestBase):
115-
'''
120+
"""
116121
Test the permittivity file is uploaded correctly
117-
'''
122+
"""
118123

119124
args = ['LWC.csv']
120125
kwargs = {'timezone': 'MST'}
@@ -144,9 +149,9 @@ class TestLWCProfile(TableTestBase):
144149

145150

146151
class TestLWCProfileB(TableTestBase):
147-
'''
152+
"""
148153
Test the permittivity file is uploaded correctly
149-
'''
154+
"""
150155

151156
args = ['LWC2.csv']
152157
kwargs = {'timezone': 'MST'}
@@ -189,9 +194,9 @@ class TestLWCProfileB(TableTestBase):
189194

190195

191196
class TestTemperatureProfile(TableTestBase):
192-
'''
197+
"""
193198
Test that a temperature profile is uploaded to the DB correctly
194-
'''
199+
"""
195200

196201
args = ['temperature.csv']
197202
kwargs = {'timezone': 'MST'}
@@ -217,9 +222,9 @@ class TestTemperatureProfile(TableTestBase):
217222

218223

219224
class TestSSAProfile(TableTestBase):
220-
'''
225+
"""
221226
Test that all profiles from an SSA file are uploaded correctly
222-
'''
227+
"""
223228

224229
args = ['SSA.csv']
225230
kwargs = {'timezone': 'MST'}
@@ -253,9 +258,9 @@ class TestSSAProfile(TableTestBase):
253258

254259

255260
class TestSMPProfile(TableTestBase):
256-
'''
261+
"""
257262
Test SMP profile is uploaded with all its attributes and valid data
258-
'''
263+
"""
259264

260265
args = ['S06M0874_2N12_20200131.CSV']
261266
kwargs = {'timezone': 'UTC', 'units': 'Newtons', 'header_sep': ':'}

tests/test_points.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import datetime
22

3-
import pytest
4-
53
from snowexsql.data import PointData
64
from snowexsql.upload import PointDataCSV
75

@@ -88,6 +86,12 @@ def test_extended_geom(self):
8886
r = self.session.query(PointData.geom).limit(1).one()
8987
assert r[0].srid == 26912
9088

89+
def test_date_accessed(self):
90+
"""
91+
Tests that the date accessed is auto assigned on upload
92+
"""
93+
result = self.session.query(PointData.date_accessed).limit(1).all()
94+
assert type(result[0][0]) is datetime.date
9195

9296
class TestGPRPointData(PointsBase):
9397
gpr_dt = datetime.date(2019, 1, 28)

tests/test_rasters.py

+38-27
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from os.path import join
2-
2+
from datetime import date
33
import numpy as np
44
from geoalchemy2.shape import to_shape
55
from geoalchemy2.types import Raster
@@ -14,63 +14,66 @@
1414

1515

1616
class TestRaster(TableTestBase):
17-
'''
17+
"""
1818
Test uploading a raster
19-
'''
19+
"""
2020

2121
# Class to use to upload the data
2222
UploaderClass = UploadRaster
2323

2424
# Positional arguments to pass to the uploader class
25-
args = [join('be_gm1_0328','w001001x.adf')]
25+
args = [join('be_gm1_0328', 'w001001x.adf')]
2626

2727
# Keyword args to pass to the uploader class
28-
kwargs = {'type':'dem', 'epsg':26912, 'description':'test'}
28+
kwargs = {'type': 'dem', 'epsg': 26912, 'description': 'test'}
2929

3030
# Always define this using a table class from data.py and is used for ORM
3131
TableClass = ImageData
3232

3333
# First filter to be applied is count_attribute == data_name
3434
count_attribute = 'type'
3535

36-
3736
# Define params which is a dictionary of test names and their args
3837
params = {
39-
'test_count': [dict(data_name='dem', expected_count=1)],
40-
'test_value': [dict(data_name='dem', attribute_to_check='description', filter_attribute='id', filter_value=1, expected='test')],
41-
'test_unique_count': [dict(data_name='dem', attribute_to_count='id', expected_count=1)]
42-
}
38+
'test_count': [dict(data_name='dem', expected_count=1)],
39+
'test_value': [dict(data_name='dem', attribute_to_check='description',
40+
filter_attribute='id', filter_value=1,
41+
expected='test')],
42+
'test_unique_count': [dict(data_name='dem', attribute_to_count='id',
43+
expected_count=1)]
44+
}
45+
4346

4447
class TestTiledRaster(DBSetup):
45-
'''
48+
"""
4649
A class to test common operations and features of tiled raster in the DB
47-
'''
50+
"""
4851

4952
def setup_class(self):
50-
'''
53+
"""
5154
Setup the database one time for testing
52-
'''
55+
"""
5356
super().setup_class()
5457
# Positional arguments to pass to the uploader class
55-
args = [join(self.data_dir, 'uavsar','uavsar_utm.amp1.real.tif')]
58+
args = [join(self.data_dir, 'uavsar', 'uavsar_utm.amp1.real.tif')]
5659

5760
# Keyword args to pass to the uploader class
58-
kwargs = {'type':'insar', 'epsg':26912, 'description':'test', 'tiled':True}
61+
kwargs = {'type': 'insar', 'epsg': 26912, 'description': 'test', 'tiled': True}
5962
# Upload two rasters (next two each other)
6063
u = UploadRaster(*args, **kwargs)
6164
u.submit(self.session)
6265

6366
def test_tiled_raster_count(self):
64-
'''
67+
"""
6568
Test two rasters uploaded
66-
'''
69+
"""
6770
records = self.session.query(ImageData.id).all()
6871
assert len(records) == 4
6972

7073
def test_tiled_raster_size(self):
71-
'''
74+
"""
7275
Tiled raster should be 500x500 in most cases (can be smaller to fit domains)
73-
'''
76+
"""
7477
rasters = self.session.query(func.ST_AsTiff(ImageData.raster)).all()
7578
datasets = raster_to_rasterio(self.session, rasters)
7679

@@ -79,9 +82,9 @@ def test_tiled_raster_size(self):
7982
assert d.height <= 500
8083

8184
def test_raster_point_retrieval(self):
82-
'''
85+
"""
8386
Test we can retrieve coordinates of a point from the database
84-
'''
87+
"""
8588

8689
# Get the first pixel as a point
8790
records = self.session.query(ST_PixelAsPoint(ImageData.raster, 1, 1)).limit(1).all()
@@ -93,19 +96,27 @@ def test_raster_point_retrieval(self):
9396
np.testing.assert_almost_equal(received.y, expected.y, 6)
9497

9598
def test_raster_union(self):
96-
'''
99+
"""
97100
Test we can retrieve coordinates of a point from the database
98-
'''
101+
"""
99102

100103
# Get the first pixel as a point
101104
rasters = self.session.query(func.ST_AsTiff(func.ST_Union(ImageData.raster, type_=Raster))).all()
102105
assert len(rasters) == 1
103106

104107
def test_raster_union2(self):
105-
'''
108+
"""
106109
Test we can retrieve coordinates of a point from the database
107-
'''
110+
"""
108111

109112
# Get the first pixel as a point
110-
merged = self.session.query(func.ST_Union(ImageData.raster, type_=Raster)).filter(ImageData.id.in_([1, 2])).all()
113+
merged = self.session.query(func.ST_Union(ImageData.raster, type_=Raster)).filter(
114+
ImageData.id.in_([1, 2])).all()
111115
assert len(merged) == 1
116+
117+
def test_date_accessed(self):
118+
"""
119+
Tests that the date accessed is auto assigned on upload
120+
"""
121+
result = self.session.query(ImageData.date_accessed).limit(1).all()
122+
assert type(result[0][0]) is date

0 commit comments

Comments
 (0)