diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4d50fc3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +tmp/ +.idea/ +__pycache__ diff --git a/README.md b/README.md index 50b57c3..f41e5be 100644 --- a/README.md +++ b/README.md @@ -4,3 +4,15 @@ Attempt at using XSLT to translate CellML 1.0 and 1.1 documents into the propose Note that it needs an XSLT 2 processor to handle namespace nodes nicely. Tested using the Saxon engine within oXygen XML and Saxon on the command line, e.g., `saxon -s:test-models/cellml1.0.xml -xsl:cellml1to2.xsl`. This is primarily an effort to enable the production of a suite of test CellML 2.0 models for use in testing the functionality of [libCellML](http://libcellml.readthedocs.io/). + +## tests + +There are some simple tests that can be run with Python, saxon, and libCellML. + +From the repository root directory run: + +`python -m unittest` + +The final result should be: + +`OK` diff --git a/cellml1to2.xsl b/cellml1to2.xsl index c5aeed9..60f9727 100644 --- a/cellml1to2.xsl +++ b/cellml1to2.xsl @@ -52,10 +52,20 @@ + + + + + + + + + + diff --git a/test-models/basic_model.cellml b/test-models/basic_model.cellml new file mode 100644 index 0000000..a863c34 --- /dev/null +++ b/test-models/basic_model.cellml @@ -0,0 +1,16 @@ + + + + + + + t + + + 1 + 3 + + + + + diff --git a/test-models/van_der_pol_model.cellml b/test-models/van_der_pol_model.cellml new file mode 100644 index 0000000..8453b12 --- /dev/null +++ b/test-models/van_der_pol_model.cellml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + time + + x + + + + y + 1 + + + + + + + + time + + y + + + + + + + + epsilon + + + 1 + + + x + 2 + + + y + + x + + 1 + + + + + diff --git a/test-scripts/__init__.py b/test-scripts/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/test-scripts/test_model.py b/test-scripts/test_model.py new file mode 100644 index 0000000..0894d69 --- /dev/null +++ b/test-scripts/test_model.py @@ -0,0 +1,52 @@ +import unittest + +import libcellml as lc + +from subprocess import Popen, PIPE + + +def run_saxon(model_name): + with Popen(["saxon", f"-s:test-models/{model_name}", "-xsl:cellml1to2.xsl"], stdout=PIPE) as proc: + return proc.stdout.read().decode() + + +class TranslationTestCase(unittest.TestCase): + + def setUp(self): + self._p = lc.Parser() + self._v = lc.Validator() + + def _validate_model(self, model_name): + translated_model = run_saxon(model_name) + + m = self._p.parseModel(translated_model) + + self._v.validateModel(m) + + def test_basic_model(self): + self._validate_model('basic_model.cellml') + + self.assertEqual(0, self._v.errorCount()) + + def test_van_der_pol_model(self): + self._validate_model('van_der_pol_model.cellml') + + self.assertEqual(0, self._v.errorCount()) + + def test_cellml_1_0_model(self): + self._validate_model('cellml1.0.xml') + + self.assertEqual(2, self._v.errorCount()) + self.assertIn('celsius', self._v.error(0).description()) + self.assertEqual('1.3.1.2', self._v.error(1).referenceHeading()) + + def test_cellml_1_1_model(self): + self._validate_model('cellml1.1.xml') + + self.assertEqual(2, self._v.errorCount()) + self.assertIn('celsius', self._v.error(0).description()) + self.assertEqual('1.3.1.2', self._v.error(1).referenceHeading()) + + +if __name__ == '__main__': + unittest.main()