def test_create_from_path(self): path = utils.path_to_text_fixture("osm.xlsx") survey = create_survey_from_path(path) path = os.path.join(os.path.dirname(__file__), 'test_expected_output', 'osm.xml') with codecs.open(path, encoding='utf-8') as f: expected_xml = f.read() self.assertXFormEqual(survey.to_xml(), expected_xml) survey = create_survey_element_from_json(survey.to_json()) self.assertXFormEqual(survey.to_xml(), expected_xml)
def test_create_from_path(self): path = utils.path_to_text_fixture("file_type.xlsx") survey = create_survey_from_path(path) path = os.path.join( os.path.dirname(__file__), 'test_expected_output', 'file_type.xml') with codecs.open(path, encoding='utf-8') as f: expected_xml = f.read() self.assertXFormEqual(survey.to_xml(), expected_xml) survey = create_survey_element_from_json(survey.to_json()) self.assertXFormEqual(survey.to_xml(), expected_xml)
def test_question_type_that_accepts_parameters__without_parameters__to_xml( self): """Should be able to round-trip survey using a un-parameterised question without error.""" # Per https://github.com/XLSForm/pyxform/issues/605 # Underlying issue was that the SurveyElement.FIELDS default for "parameters" was # a string, but in MultipleChoiceQuestion.build_xml a dict is assumed, because # xls2json.parse_parameters always returns a dict. js = """ { "type": "survey", "name": "ExchangeRate", "children": [ { "itemset": "pain_locations.xml", "label": "Location of worst pain this week.", "name": "pweek", "type": "select one" } ] } """ create_survey_element_from_json(str_or_path=js).to_xml()
def survey(self): new_doc = json.dumps(self.new_doc) _survey = builder.create_survey_element_from_json(new_doc) return _survey
def test_load_from_dump(self): for filename, survey in self.surveys.items(): survey.json_dump() path = survey.get_name() + ".json" survey_from_dump = create_survey_element_from_json(path) self.assertEqual(survey.to_dict(), survey_from_dump.to_dict())