diff --git a/pyxform/tests/example_xls/survey_no_name.xlsx b/pyxform/tests/example_xls/survey_no_name.xlsx new file mode 100644 index 000000000..76097a850 Binary files /dev/null and b/pyxform/tests/example_xls/survey_no_name.xlsx differ diff --git a/pyxform/tests/test_expected_output/survey_no_name.xml b/pyxform/tests/test_expected_output/survey_no_name.xml new file mode 100644 index 000000000..b37d087e6 --- /dev/null +++ b/pyxform/tests/test_expected_output/survey_no_name.xml @@ -0,0 +1,23 @@ + + + + data + + + + + + + + + + + + + + + + + + + diff --git a/pyxform/tests/xls2json_tests.py b/pyxform/tests/xls2json_tests.py index de6e1114c..a81bd1a2d 100644 --- a/pyxform/tests/xls2json_tests.py +++ b/pyxform/tests/xls2json_tests.py @@ -242,3 +242,13 @@ def test_a_unicode_csv_works(self): utf_csv_path = utils.path_to_text_fixture("utf_csv.csv") dict_value = csv_to_dict(utf_csv_path) self.assertTrue("\\ud83c" in json.dumps(dict_value)) + + +class DefaultToSurveyTest(TestCase): + def test_default_sheet_name_to_survey(self): + xls_path = utils.path_to_text_fixture("survey_no_name.xlsx") + dict_value = xls_to_dict(xls_path) + print (json.dumps(dict_value)) + self.assertTrue("survey" in json.dumps(dict_value)) + self.assertTrue("state" in json.dumps(dict_value)) + self.assertTrue("The State" in json.dumps(dict_value)) diff --git a/pyxform/tests/xlsform_spec_test.py b/pyxform/tests/xlsform_spec_test.py index c87b98516..80b7dc7a0 100644 --- a/pyxform/tests/xlsform_spec_test.py +++ b/pyxform/tests/xlsform_spec_test.py @@ -171,5 +171,27 @@ def runTest(self): os.remove(self.output_path) +class DefaultSurveySheetTest(XFormTestCase): + maxDiff = None + + def runTest(self): + filename = "survey_no_name.xlsx" + self.get_file_path(filename) + expected_output_path = os.path.join( + DIR, "test_expected_output", self.root_filename + ".xml" + ) + + warnings = [] + json_survey = pyxform.xls2json.parse_file_to_json( + self.path_to_excel_file, warnings=warnings + ) + survey = pyxform.create_survey_element_from_dict(json_survey) + survey.print_xform_to_file(self.output_path, warnings=warnings) + + with codecs.open(expected_output_path, "rb", encoding="utf-8") as expected_file: + with codecs.open(self.output_path, "rb", encoding="utf-8") as actual_file: + self.assertXFormEqual(expected_file.read(), actual_file.read()) + + if __name__ == "__main__": unittest.main() diff --git a/pyxform/xls2json_backends.py b/pyxform/xls2json_backends.py index c57200902..6f4b7a543 100644 --- a/pyxform/xls2json_backends.py +++ b/pyxform/xls2json_backends.py @@ -209,7 +209,12 @@ def slugify(s): for sheet in workbook.sheets(): # Do not process sheets that have nothing to do with XLSForm. if sheet.name not in constants.SUPPORTED_SHEET_NAMES: - continue + if len(workbook.sheets()) == 1: + result[constants.SURVEY], result[ + "%s_header" % constants.SURVEY + ] = xls_to_dict_normal_sheet(sheet) + else: + continue if sheet.name == constants.CASCADING_CHOICES: result[sheet.name] = _xls_to_dict_cascade_sheet(sheet) else: