-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
58 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
|
||
import abc | ||
import unittest | ||
from tempfile import TemporaryDirectory | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
ddundo
Author
Member
|
||
|
||
from firedrake import * | ||
|
||
|
@@ -108,24 +109,6 @@ def test_extract_by_subinterval(self): | |
for f in sub_data[self.field][label]: | ||
self.assertTrue(isinstance(f, Function)) | ||
|
||
def test_export_extension_error(self): | ||
with self.assertRaises(ValueError) as cm: | ||
self.solution_data.export("test.ext") | ||
msg = ( | ||
"Output file format not recognised: 'test.ext'." | ||
+ " Supported formats are '.pvd' and '.h5'." | ||
) | ||
self.assertEqual(str(cm.exception), msg) | ||
|
||
def test_export_field_error(self): | ||
with self.assertRaises(ValueError) as cm: | ||
self.solution_data.export("test.pvd", export_field_types="test") | ||
msg = ( | ||
"Field types ['test'] not recognised." | ||
+ f" Available types are {self.solution_data.labels}." | ||
) | ||
self.assertEqual(str(cm.exception), msg) | ||
|
||
|
||
class TestSteadyForwardSolutionData(BaseTestCases.TestFunctionData): | ||
""" | ||
|
@@ -231,5 +214,62 @@ def test_extract_by_subinterval(self): | |
self.assertTrue(isinstance(f, Function)) | ||
|
||
|
||
class TestExportFunctionData(BaseTestCases.TestFunctionData): | ||
""" | ||
Unit tests for exporting and checkpointing :class:`~.FunctionData`. | ||
""" | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
cls.tmpdir = TemporaryDirectory() | ||
|
||
def setUp(self): | ||
super().setUpUnsteady() | ||
self.labels = ("forward", "forward_old") | ||
|
||
def _create_function_data(self): | ||
self.solution_data = ForwardSolutionData( | ||
self.time_partition, self.function_spaces | ||
) | ||
self.solution_data._create_data() | ||
|
||
def test_export_extension_error(self): | ||
with self.assertRaises(ValueError) as cm: | ||
self.solution_data.export("test.ext") | ||
msg = ( | ||
"Output file format not recognised: 'test.ext'." | ||
+ " Supported formats are '.pvd' and '.h5'." | ||
) | ||
self.assertEqual(str(cm.exception), msg) | ||
|
||
def test_export_field_error(self): | ||
with self.assertRaises(ValueError) as cm: | ||
self.solution_data.export("test.pvd", export_field_types="test") | ||
msg = ( | ||
"Field types ['test'] not recognised." | ||
+ f" Available types are {self.solution_data.labels}." | ||
) | ||
self.assertEqual(str(cm.exception), msg) | ||
|
||
def test_export_pvd(self): | ||
with TemporaryDirectory() as tmpdir: | ||
export_filepath = os.path.join(tmpdir, "test.pvd") | ||
self.solution_data.export(export_filepath) | ||
self.assertTrue(os.path.exists(export_filepath)) | ||
|
||
def test_export_pvd_ic(self): | ||
ic = {field: Function(fs[0]) for field, fs in self.function_spaces.items()} | ||
with TemporaryDirectory() as tmpdir: | ||
export_filepath = os.path.join(tmpdir, "test.pvd") | ||
self.solution_data.export(export_filepath, initial_condition=ic) | ||
self.assertTrue(os.path.exists(export_filepath)) | ||
|
||
def test_export_h5(self): | ||
with TemporaryDirectory() as tmpdir: | ||
export_filepath = os.path.join(tmpdir, "test.h5") | ||
self.solution_data.export(export_filepath) | ||
self.assertTrue(os.path.exists(export_filepath)) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
Nice! I hadn't heard of this before but it sounds like a really useful utility. We should use this more often.