diff --git a/tests/example_xls/instance_xmlns_test.xls b/tests/example_xls/instance_xmlns_test.xls deleted file mode 100644 index 3978bfe91..000000000 Binary files a/tests/example_xls/instance_xmlns_test.xls and /dev/null differ diff --git a/tests/example_xls/instance_xmlns_test.xml b/tests/example_xls/instance_xmlns_test.xml deleted file mode 100644 index a037f6b76..000000000 --- a/tests/example_xls/instance_xmlns_test.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - foo - - - - - - - - - - - - - - - - - - - yes - - - - no - - - - diff --git a/tests/test_settings.py b/tests/test_settings.py new file mode 100644 index 000000000..e61d89cc7 --- /dev/null +++ b/tests/test_settings.py @@ -0,0 +1,47 @@ +from tests.pyxform_test_case import PyxformTestCase + + +class TestSettings(PyxformTestCase): + + def test_instance_xmlns__is_set__custom_xmlns(self): + """Should find the instance_xmlns value in the instance xmlns attribute.""" + md = """ + | settings | + | | instance_xmlns | + | | 1234 | + | survey | | | | + | | type | name | label | + | | text | q1 | hello | + """ + self.assertPyxformXform( + md=md, + xml__xpath_match=[ + """ + /h:html/h:head/x:model/x:instance/*[ + local-name()='test_name' + and @id='test_id' + and namespace-uri()='1234' + ] + """ + ] + ) + + def test_instance_xmlns__not_set__default_xmlns(self): + """Should find the default xmlns for the instance element.""" + md = """ + | survey | | | | + | | type | name | label | + | | text | q1 | hello | + """ + self.assertPyxformXform( + md=md, + xml__xpath_match=[ + """ + /h:html/h:head/x:model/x:instance/*[ + local-name()='test_name' + and @id='test_id' + and namespace-uri()='http://www.w3.org/2002/xforms' + ] + """ + ], + ) diff --git a/tests/tests_by_file.py b/tests/tests_by_file.py deleted file mode 100644 index 43daba818..000000000 --- a/tests/tests_by_file.py +++ /dev/null @@ -1,52 +0,0 @@ -# -*- coding: utf-8 -*- -""" -Tests by file. Runs through a list of *.xls files, and expects that the output -for a *.xml with a matching prefix before the . is as expected. Possibly risky: -all tests in this file are defined according to matching files. -""" - -import codecs -import os -import sys -import xml.etree.ElementTree as ETree -from unittest import TestCase - -from formencode.doctest_xml_compare import xml_compare - -import pyxform -from pyxform import xls2json -from tests import utils - - -class MainTest(TestCase): - def runTest(self): - files_to_test = ["instance_xmlns_test.xls"] - for file_to_test in files_to_test: - path_to_excel_file = utils.path_to_text_fixture(file_to_test) - - # Get the xform output path: - directory, filename = os.path.split(path_to_excel_file) - root_filename, ext = os.path.splitext(filename) - path_to_output_xform = os.path.join(directory, root_filename + "_output.xml") - path_to_expected_xform = os.path.join(directory, root_filename + ".xml") - - # Do the conversion: - json_survey = xls2json.parse_file_to_json( - path_to_excel_file, default_name=root_filename - ) - survey = pyxform.create_survey_element_from_dict(json_survey) - survey.print_xform_to_file(path_to_output_xform) - - # Compare with the expected output: - with codecs.open( - path_to_expected_xform, "rb", encoding="utf-8" - ) as expected_file: - expected = ETree.fromstring(expected_file.read()) - result = ETree.fromstring(survey.to_xml()) - - def write_line(x): - sys.stdout.write(x + "\n") - - reporter = write_line - self.assertTrue(xml_compare(expected, result, reporter=reporter)) - os.remove(path_to_output_xform)