1 | """Automatic verification of ANUGA using Patong Beach validation scenario. |
---|
2 | See functions exercised by this wrapper for more details and also the publication (TBA). |
---|
3 | """ |
---|
4 | |
---|
5 | import unittest |
---|
6 | import os |
---|
7 | from subprocess import Popen, PIPE |
---|
8 | |
---|
9 | |
---|
10 | def get_free_memory(): |
---|
11 | """Get available memory. Linux only. |
---|
12 | """ |
---|
13 | |
---|
14 | p = Popen('free', shell=True, |
---|
15 | stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True) |
---|
16 | |
---|
17 | if p.stdout is not None: |
---|
18 | for line in p.stdout.readlines(): |
---|
19 | if line.startswith('Mem'): |
---|
20 | fields = line.split() |
---|
21 | mem = int(fields[1]) # Total memory |
---|
22 | else: |
---|
23 | mem = None |
---|
24 | |
---|
25 | |
---|
26 | return mem |
---|
27 | |
---|
28 | |
---|
29 | class Test_flow(unittest.TestCase): |
---|
30 | def setUp(self): |
---|
31 | for file in os.listdir('.'): |
---|
32 | if file.endswith('.stdout') or\ |
---|
33 | file.endswith('.sww') or\ |
---|
34 | file.endswith('.msh'): |
---|
35 | os.remove(file) |
---|
36 | |
---|
37 | |
---|
38 | def tearDown(self): |
---|
39 | pass |
---|
40 | |
---|
41 | def test_patong_validation(self): |
---|
42 | """Exercise Patong Validation Scenario for three resolutions and |
---|
43 | compare timeseries from modelled results against reference model. |
---|
44 | """ |
---|
45 | |
---|
46 | # Bail out if there is insufficient memory. |
---|
47 | # This works only on *nix systems |
---|
48 | mem = get_free_memory() |
---|
49 | if mem is None: |
---|
50 | msg = 'No information about available memory: ' |
---|
51 | msg += 'Skipping Patong beach validation' |
---|
52 | raise Exception(msg) |
---|
53 | |
---|
54 | if mem < 8000000: |
---|
55 | msg = 'Insufficient memory to run Patong beach validation. ' |
---|
56 | msg += 'Got %i need at least 8GB. ' % mem |
---|
57 | msg += 'Skipping Patong beach validation' |
---|
58 | raise Exception(msg) |
---|
59 | |
---|
60 | #print |
---|
61 | s = 'test_patong_scenario.py' |
---|
62 | #print s |
---|
63 | res = os.system('python %s > test_patong_scenario.stdout' % s) |
---|
64 | #assert res == 0 |
---|
65 | |
---|
66 | |
---|
67 | #------------------------------------------------------------- |
---|
68 | if __name__ == '__main__': |
---|
69 | suite = unittest.makeSuite(Test_flow, 'test') |
---|
70 | runner = unittest.TextTestRunner(verbosity=2) |
---|
71 | runner.run(suite) |
---|