--- /dev/null
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+"""
+Test for conversion of srf to med usgin medcoupling to rebuild boundary on
+segment
+"""
+
+# Modules Python
+from os import path, environ
+import tempfile
+import subprocess as sp
+import sys
+
+import numpy as np
+
+from data_manip.conversion.stbtel_converter import run_converter
+from data_manip.extraction.telemac_file import TelemacFile
+
+
+def create_test_file(file_name):
+ """
+ Create a triforce file and its boudary_file
+ """
+
+ if file_name.endswith("med"):
+ bnd_file = path.splitext(file_name)[0] + ".bnd"
+ else:
+ bnd_file = path.splitext(file_name)[0] + ".cli"
+
+ points = np.array(\
+ [[0., 0.],
+ [1., 0.],
+ [2., 0.],
+ [0.5, 1.],
+ [1.5, 1.],
+ [1., 2.]])
+ ikle = [[0, 1, 3],
+ [1, 4, 3],
+ [1, 2, 4],
+ [3, 4, 5],
+ ]
+
+ res = TelemacFile(file_name, bnd_file=bnd_file, access='w')
+ res.add_header('Zelda triforce', date=[1986, 2, 21, 0, 0, 0])
+ res.add_mesh(points[:, 0], points[:, 1], ikle)
+ res.add_variable('dummy', '')
+
+ if file_name.endswith("med"):
+ ikle_bnd = [[0, 3], [3, 5], [5, 4], [4, 2], [2, 1], [1, 0]]
+ lihbor = [2, 2, 2, 2, 4, 4]
+ liubor = [2, 2, 2, 2, 5, 5]
+ livbor = [2, 2, 2, 2, 5, 5]
+ else:
+ ikle_bnd = [0, 3, 5, 4, 2, 1]
+ lihbor = [4, 2, 2, 2, 4, 4]
+ liubor = [5, 2, 2, 2, 5, 5]
+ livbor = [5, 2, 2, 2, 5, 5]
+
+ res.add_bnd(ikle_bnd, lihbor=lihbor, liubor=liubor, livbor=livbor)
+
+ res.write()
+ res.close()
+
+ return bnd_file
+
+#with tempfile.TemporaryDirectory() as tmp_dir:
+tmp_dir = tempfile.mkdtemp()
+ref_srf = path.join(tmp_dir, "ref.srf")
+ref_med = path.join(tmp_dir, "ref.med")
+
+ref_srf_bnd = create_test_file(ref_srf)
+ref_med_bnd = create_test_file(ref_med)
+
+output_file = path.join(tmp_dir, "test.med")
+output_bnd_file = path.splitext(output_file)[0] + ".bnd"
+
+print("ref_srf", ref_srf)
+print("ref_srf_bnd", ref_srf_bnd)
+print("ref_med", ref_med)
+print("ref_med_bnd", ref_med_bnd)
+print("output_file", output_file)
+print("output_bndfile", output_bnd_file)
+
+cmd = ["converter.py", "srf2med", ref_srf, "-b", ref_srf_bnd, output_file]
+
+if sys.platform == "win32":
+ code = sp.call(cmd, shell=True)
+else:
+ code = sp.call(cmd)
+
+if code != 0:
+ sys.exit(code)
+
+conv_res = TelemacFile(output_file, bnd_file=output_bnd_file)
+ref_res = TelemacFile(ref_med, bnd_file=ref_med_bnd)
+
+assert conv_res.typ_bnd_elem == ref_res.typ_bnd_elem, "type res/ref: {}/{}".format(conv_res.typ_bnd_elem, ref_res.typ_bnd_elem)
+assert conv_res.nelebd == ref_res.nelebd, "nelebd res/ref: {}/{}".format(conv_res.nelebd, ref_res.nelebd)