Debian Codegraph @

python/test/unit/io/test_XML_table.py

raw
1 """Unit tests for the XML io library for Tables"""
2
3 # Copyright (C) 2016 Simon Funke and Marie E. Rognes
4 #
5 # This file is part of DOLFIN.
6 #
7 # DOLFIN is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Lesser General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # DOLFIN is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Lesser General Public License for more details.
16 #
17 # You should have received a copy of the GNU Lesser General Public License
18 # along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
19
20 import pytest
21 from dolfin import *
22 from dolfin_utils.test import cd_tempdir
23
24
25 def test_write_and_read_table(cd_tempdir):
26 # Do something that takes time
27 x = PETScVector(MPI.comm_world, 197)
28
29 if MPI.rank(MPI.comm_world) == 0:
30 # Create table for timings
31 t = timings(TimingClear.keep, [TimingType.wall, TimingType.system])
32 t_str = t.str(True)
33
34 # Write table to file
35 file = File(MPI.comm_self, "my_table.xml")
36 file << t
37 del t
38 del file
39
40 # Read table from file
41 file = File(MPI.comm_self, "my_table.xml")
42 t = Table("My Table")
43 file >> t
44
45 t_new_str = t.str(True)
46
47 assert t_new_str == t_str