-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_dfs_custom_block.py
72 lines (56 loc) · 2.65 KB
/
test_dfs_custom_block.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
67
68
69
70
71
72
import unittest
from mikecore.DfsFileFactory import DfsFileFactory
from mikecore.DfsFile import *
from numpy.testing import *
from tests.test_util import *
class Test_dfs_custom_block(unittest.TestCase):
def test_dfs2(self):
dfsFile = DfsFileFactory.DfsGenericOpen("testdata/OresundHD.dfs2")
assert_equal(1, len(dfsFile.FileInfo.CustomBlocks))
customBlock = dfsFile.FileInfo.CustomBlocks[0];
assert_equal("M21_Misc", customBlock.Name);
assert_equal(DfsSimpleType.Float, customBlock.SimpleType);
assert_equal(7, len(customBlock.Values));
assert_equal(327, customBlock.Values[0]) # Orientation - matching that in the projection info
assert_allclose(0.2, customBlock.Values[1]) # Drying depth
assert_equal(-900, customBlock.Values[2]) # -900 = contains geographic information (projection)
assert_equal(10, customBlock.Values[3]); # Land value
assert_equal(0, customBlock.Values[4]);
assert_equal(0, customBlock.Values[5]);
assert_equal(0, customBlock.Values[6]);
dfsFile.Close()
def test_dfsu(self):
dfsFile = DfsFileFactory.DfsGenericOpen("testdata/OresundHD.dfsu")
assert_equal(1, len(dfsFile.FileInfo.CustomBlocks))
customBlock = dfsFile.FileInfo.CustomBlocks[0];
assert_equal(DfsSimpleType.Int, customBlock.SimpleType);
assert_equal("MIKE_FM", customBlock.Name);
assert_equal(5, len(customBlock.Values));
assert_equal(2057, customBlock.Values[0]);
assert_equal(3636, customBlock.Values[1]);
assert_equal(2, customBlock.Values[2]);
assert_equal(0, customBlock.Values[3]);
assert_equal(0, customBlock.Values[4]);
dfsFile.Close()
def test_UpdateCustomBlockDataTest(self):
originalFilename = "testdata/OresundHD.dfs2";
filename = "testdata/testtmp/test_copy_OresundHD_cb.dfs2";
testUtil.copy_file(originalFilename, filename)
# Check initial value
dfsFile = DfsFileFactory.DfsGenericOpen(filename);
fileInfo = dfsFile.FileInfo;
customBlock = fileInfo.CustomBlocks[0];
assert_equal(10, customBlock.Values[3]);
dfsFile.Close();
# Modify value
dfsFile = DfsFileFactory.DfsGenericOpenEdit(filename);
fileInfo = dfsFile.FileInfo;
customBlock = fileInfo.CustomBlocks[0];
customBlock.Values[3] = 25;
dfsFile.Close();
# Check new value
dfsFile = DfsFileFactory.DfsGenericOpen(filename);
fileInfo = dfsFile.FileInfo;
customBlock = fileInfo.CustomBlocks[0];
assert_equal(25, customBlock.Values[3]);
dfsFile.Close();