Skip to content

Commit 57e48f9

Browse files
committed
Add some test code
Will test the generation of grids for tiling Run with `py.test`
1 parent f006a71 commit 57e48f9

File tree

4 files changed

+67
-5
lines changed

4 files changed

+67
-5
lines changed

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,7 @@ docs/_build/
5757
target/
5858

5959
# IntelliJ/PyCharm
60-
.idea
60+
.idea
61+
62+
# Test stuff
63+
.hypothesis

setup.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,13 @@
1717
'numpy',
1818
'netCDF4',
1919
],
20-
entry_points='''
21-
[console_scripts]
22-
datacube_ingest=ingestor.ingest_from_yaml:main
23-
''',
20+
tests_require=[
21+
'pytest',
22+
],
23+
24+
entry_points={
25+
'console_scripts': [
26+
'datacube_ingest = ingestor.ingest_from_yaml:main'
27+
]
28+
},
2429
)

tests/__init__.py

Whitespace-only changes.

tests/test_grids.py

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
from collections import namedtuple
2+
3+
# Implementation code
4+
5+
TileDef = namedtuple('TileDef', 'xstart ystart xwidth ywidth')
6+
7+
def create_grid_from_extent(width, height, xtile, ytile):
8+
9+
return [TileDef(xstart, ystart, xtile, ytile)
10+
for xstart in xrange(0, width, xtile)
11+
for ystart in xrange(0, height, ytile)]
12+
13+
14+
def round_up_divide(a, b):
15+
"""Divide a / b and round up. Integers"""
16+
return (a+(-a%b))//b
17+
18+
## Test Code
19+
ImageDef = namedtuple('ImageDef', 'width height tilewidth tileheight')
20+
def test_simple_grid():
21+
imagedef = ImageDef(1000, 1000, 100, 100)
22+
create_and_validate_grid(imagedef)
23+
24+
def test_trivial_grid():
25+
imagedef = ImageDef(100, 100, 100, 100)
26+
create_and_validate_grid(imagedef)
27+
28+
def test_slightly_larger_grid():
29+
imagedef = ImageDef(1001, 1000, 100, 100)
30+
create_and_validate_grid(imagedef)
31+
32+
33+
def create_and_validate_grid(imagedef):
34+
tiles = create_grid_from_extent(*imagedef)
35+
36+
num_expected_tiles = round_up_divide(imagedef.width, imagedef.tilewidth) * round_up_divide(imagedef.height, imagedef.tileheight)
37+
assert(len(tiles) == num_expected_tiles)
38+
total_width = 0
39+
for t in tiles:
40+
if t.ystart == 0:
41+
total_width += t.xwidth
42+
assert(type(t) == TileDef)
43+
assert(t.xwidth <= imagedef.tilewidth)
44+
assert(t.xstart < imagedef.width)
45+
assert(t.xstart + t.xwidth <= imagedef.width + imagedef.tilewidth)
46+
47+
assert(total_width >= imagedef.width)
48+
49+
50+
def test_expanded_extents():
51+
pass
52+
53+
def test_gridded_geo_box():
54+
pass

0 commit comments

Comments
 (0)