-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_simplesimdb.py
86 lines (79 loc) · 2.65 KB
/
test_simplesimdb.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import pytest
import simplesimdb as sim
import os.path
# Run with pytest -s . to see stdout output
def test_construction_and_destruction():
print ( "TEST")
m = sim.Manager()
assert os.path.isdir( "data")
m.delete_all()
assert not os.path.isdir( "data")
def test_creation() :
print ( "TEST CREATION")
m = sim.Manager( directory='creation_test', executable='cp', filetype = 'json')
assert m.directory == "creation_test"
assert m.executable == "cp"
assert m.filetype == "json"
inputdata = {"Hello": "World"}
m.create( inputdata)
content = m.table( )
assert content == [inputdata]
m.delete_all()
assert not os.path.isdir( m.directory)
def test_selection () :
print ( "TEST SELECTION")
m = sim.Manager( directory='selection_test', executable='cp', filetype = 'json')
inputdata = {"Hello": "World"}
inputdata2 = {"Hello": "World!"}
m.create( inputdata)
m.create( inputdata2)
data = m.select( inputdata )
assert os.path.isfile( data)
assert data == m.outfile( inputdata)
m.delete_all()
assert not os.path.isdir( m.directory)
def test_restart () :
print ( "TEST RESTART")
m = sim.Manager( directory='restart_test', executable='touch', filetype = 'th')
inputdata = {"Hello": "World"}
for i in range(0,17) :
m.create( inputdata, i)
count = m.count( inputdata)
assert count == 17
data = m.select( inputdata, 3)
assert os.path.isfile( data)
inputdata2 = {"Hello2": "World"}
for i in range(0,7) :
m.create( inputdata2, i)
content = m.table()
# Check ordered content
assert content == [inputdata2,inputdata]
files = m.files()
assert( len(files) == 24)
m.delete_all()
assert not os.path.isdir( m.directory)
def test_named_creation() :
print ( "TEST NAMED CREATION")
m = sim.Manager( directory='creation_named_test', executable='touch', filetype = 'json')
inputdata = {"Hello": "World"}
m.create( inputdata, 0)
m.delete(inputdata, 0)
m.create(inputdata, 0, "hello")
m.create(inputdata, 1, "hello")
content = m.table( )
print( m.files())
assert content == [inputdata]
m.delete_all()
assert not os.path.isdir( m.directory)
def test_repeater() :
print( "TEST REPEATER")
m = sim.Repeater( "touch", "temp.json", "temp.nc")
inputdata = {"Hello": "World"}
m.run( inputdata, error="display", stdout="display")
assert os.path.isfile( "temp.json")
assert os.path.isfile( "temp.nc")
m.executable="echo"
m.run( inputdata, error="display", stdout="display")
m.clean()
assert not os.path.isfile( "temp.json")
assert not os.path.isfile( "temp.nc")