コード例 #1
0
 def test_xls_to_csv(self):
     specify_other_xls = utils.path_to_text_fixture("specify_other.xls")
     converted_xls = convert_file_to_csv_string(specify_other_xls)
     specify_other_csv = utils.path_to_text_fixture("specify_other.csv")
     converted_csv = convert_file_to_csv_string(specify_other_csv)
     # print "csv:"
     # print converted_csv
     # print "xls:"
     # print converted_xls
     self.assertEqual(converted_csv, converted_xls)
コード例 #2
0
ファイル: xls2json_tests.py プロジェクト: ChandniD/pyxform
 def test_equivalency(self):
     equivalent_fixtures = ['group', 'loop',  #'gps',
             'specify_other', 'include', 'text_and_integer', \
             'include_json', 'yes_or_no_question']
     for fixture in equivalent_fixtures:
         xls_path = utils.path_to_text_fixture("%s.xls" % fixture)
         csv_path = utils.path_to_text_fixture("%s.csv" % fixture)
         xls_inp = xls_to_dict(xls_path)
         csv_inp = csv_to_dict(csv_path)
         self.assertEqual(csv_inp, xls_inp)
コード例 #3
0
 def test_xls_to_csv(self):
     specify_other_xls = utils.path_to_text_fixture("specify_other.xls")
     converted_xls = convert_file_to_csv_string(specify_other_xls)
     specify_other_csv = utils.path_to_text_fixture("specify_other.csv")
     converted_csv = convert_file_to_csv_string(specify_other_csv)
     # print "csv:"
     # print converted_csv
     # print "xls:"
     # print converted_xls
     self.assertEqual(converted_csv, converted_xls)
コード例 #4
0
 def test_equivalency(self):
     equivalent_fixtures = ['group', 'loop',  #'gps',
             'specify_other', 'include', 'text_and_integer', \
             'include_json', 'yes_or_no_question']
     for fixture in equivalent_fixtures:
         xls_path = utils.path_to_text_fixture("%s.xls" % fixture)
         csv_path = utils.path_to_text_fixture("%s.csv" % fixture)
         xls_inp = xls_to_dict(xls_path)
         csv_inp = csv_to_dict(csv_path)
         self.maxDiff = None
         self.assertEqual(csv_inp, xls_inp)
コード例 #5
0
    def test_hidden(self):
        x = SurveyReader(utils.path_to_text_fixture("hidden.xls"))
        x_results = x.to_json_dict()

        expected_dict = [
            {
                u'type': u'hidden',
                u'name': u'hidden_test'
            },
            {
                'children': [
                    {
                        'bind': {
                            'calculate': "concat('uuid:', uuid())",
                            'readonly': 'true()'
                        },
                        'name': 'instanceID',
                        'type': 'calculate'
                    }
                ],
                'control': {
                    'bodyless': True
                },
                'name': 'meta',
                'type': 'group'
            }
        ]
        self.assertEqual(x_results[u"children"], expected_dict)
コード例 #6
0
ファイル: xls2json_tests.py プロジェクト: bderenzi/pyxform
    def test_table(self):
        x = SurveyReader(utils.path_to_text_fixture("simple_loop.xls"))

        expected_dict = {
            u"type": u"survey",
            u"name": u"simple_loop",
            u"id_string": u"simple_loop",
            u"default_language": u"default",
            u"title": u"simple_loop",
            u"children": [
                {
                    u"children": [
                        {
                            u"type": u"integer",
                            u"name": u"count",
                            u"label": {u"English": u"How many are there in this group?"},
                        }
                    ],
                    u"type": u"loop",
                    u"name": u"my_table",
                    u"columns": [
                        {u"name": u"col1", u"label": {u"English": u"Column 1"}},
                        {u"name": u"col2", u"label": {u"English": u"Column 2"}},
                    ],
                    u"label": {u"English": u"My Table"},
                }
            ],
        }
        self.maxDiff = None
        self.assertEqual(x.to_json_dict(), expected_dict)
コード例 #7
0
    def test_simple_yes_or_no_question(self):
        x = SurveyReader(utils.path_to_text_fixture("yes_or_no_question.xls"))
        x_results = x.to_json_dict()

        expected_dict = [{
            u'label': {
                u'english': u'have you had a good day today?'
            },
            u'type':
            u'select one',
            u'name':
            u'good_day',
            u'choices': [{
                u'label': {
                    u'english': u'yes'
                },
                u'name': u'yes'
            }, {
                u'label': {
                    u'english': u'no'
                },
                u'name': u'no'
            }]
        }]
        self.assertEqual(x_results[u"children"], expected_dict)
コード例 #8
0
 def setUp(self):
     self.excel_files = [
         "gps.xls",
         #"include.xls",
         "specify_other.xls",
         "loop.xls",
         "text_and_integer.xls",
         # todo: this is looking for json that is created (and
         # deleted) by another test, is should just add that json
         # to the directory.
         # "include_json.xls",
         "simple_loop.xls",
         "yes_or_no_question.xls",
         "xlsform_spec_test.xlsx",
         "group.xls",
     ]
     self.surveys = {}
     self.this_directory = os.path.dirname(__file__)
     for filename in self.excel_files:
         path = utils.path_to_text_fixture(filename)
         try:
             self.surveys[filename] = create_survey_from_path(path)
         except Exception as e:
             print("Error on : " + filename)
             raise e
コード例 #9
0
    def test_gps(self):
        x = SurveyReader(utils.path_to_text_fixture("gps.xls"))

        expected_dict = [
            {
                u'type': u'gps', u'name': u'location', u'label': u'GPS'},
            {
                'children': [
                    {
                        'bind': {
                            'calculate': "concat('uuid:', uuid())",
                            'readonly': 'true()'
                        },
                        'name': 'instanceID',
                        'type': 'calculate'
                    }
                ],
                'control': {
                    'bodyless': True
                },
                'name': 'meta',
                'type': 'group'
            }]

        self.assertEqual(x.to_json_dict()[u"children"], expected_dict)
コード例 #10
0
ファイル: group_test.py プロジェクト: ChandniD/pyxform
 def test_json(self):
     x = SurveyReader(utils.path_to_text_fixture("group.xls"))
     x_results = x.to_dict()
     expected_dict = {
         u'name': 'group',
         u'type': u'survey',
         u'children': [
             {
                 u'name': u'family_name',
                 u'type': u'text',
                 u'label': {u'English': u"What's your family name?"}
                 },
             {
                 u'name': u'father',
                 u'type': u'group',
                 u'label': {u'English': u'Father'},
                 u'children': [
                     {
                         u'name': u'phone_number',
                         u'type': u'phone number',
                         u'label': {u'English': u"What's your father's phone number?"}
                         },
                     {
                         u'name': u'age',
                         u'type': u'integer',
                         u'label': {u'English': u'How old is your father?'}
                         }
                     ],
                 }
             ],
         }
     self.assertEqual(x_results, expected_dict)
コード例 #11
0
ファイル: xls2json_tests.py プロジェクト: Topol/pyxform
    def test_table(self):
        x = SurveyReader(utils.path_to_text_fixture("simple_loop.xls"))

        expected_dict = {
            u'type': u'survey',
            u'name': u'simple_loop',
            u'id_string': u'simple_loop',
            u'default_language': u'default',
            u'title': u'simple_loop',
            u'children': [
                {
                    u'children': [
                        {
                            u'type': u'integer',
                            u'name': u'count',
                            u'label': {u'English': u'How many are there in this group?'}
                            }
                        ],
                    u'type': u'loop',
                    u'name': u'my_table',
                    u'columns': [
                        {
                            u'name': u'col1',
                            u'label': {u'English': u'Column 1'}
                            },
                        {
                            u'name': u'col2',
                            u'label': {u'English': u'Column 2'}
                            }
                        ],
                    u'label': {u'English': u'My Table'}
                    }]}
        self.maxDiff = None
        self.assertEqual(x.to_json_dict(), expected_dict)
コード例 #12
0
    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)
            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())
                reporter = lambda x: sys.stdout.write(x + "\n")
                self.assertTrue(
                    xml_compare(expected, result, reporter=reporter))
            os.remove(path_to_output_xform)
コード例 #13
0
    def test_gps(self):
        x = SurveyReader(utils.path_to_text_fixture("gps.xls"))

        expected_dict = [{
            u'type': u'gps',
            u'name': u'location',
            u'label': u'GPS'
        }, {
            'children': [{
                'bind': {
                    'calculate': "concat('uuid:', uuid())",
                    'readonly': 'true()'
                },
                'name': 'instanceID',
                'type': 'calculate'
            }],
            'control': {
                'bodyless': True
            },
            'name':
            'meta',
            'type':
            'group'
        }]

        self.assertEqual(x.to_json_dict()[u"children"], expected_dict)
コード例 #14
0
    def test_text_and_integer(self):
        x = SurveyReader(utils.path_to_text_fixture("text_and_integer.xls"))

        expected_dict = [{
            u'label': {
                u'english': u'What is your name?'
            },
            u'type': u'text',
            u'name': u'your_name'
        }, {
            u'label': {
                u'english': u'How many years old are you?'
            },
            u'type': u'integer',
            u'name': u'your_age'
        }, {
            u'children': [{
                u'bind': {
                    'calculate': "concat('uuid:', uuid())",
                    'readonly': 'true()'
                },
                u'name': 'instanceID',
                u'type': 'calculate'
            }],
            u'control': {
                'bodyless': True
            },
            u'name':
            'meta',
            u'type':
            u'group'
        }]

        self.assertEqual(x.to_json_dict()[u"children"], expected_dict)
コード例 #15
0
 def setUp(self):
     self.excel_files = [
         "gps.xls",
         #"include.xls",
         "specify_other.xls",
         "loop.xls",
         "text_and_integer.xls",
         # todo: this is looking for json that is created (and
         # deleted) by another test, is should just add that json
         # to the directory.
         # "include_json.xls",
         "simple_loop.xls",
         "yes_or_no_question.xls",
         "xlsform_spec_test.xlsx",
         "group.xls",
     ]
     self.surveys = {}
     self.this_directory = os.path.dirname(__file__)
     for filename in self.excel_files:
         path = utils.path_to_text_fixture(filename)
         try:
             self.surveys[filename] = create_survey_from_path(path)
         except Exception as e:
             print("Error on : " + filename)
             raise e
コード例 #16
0
    def test_hidden(self):
        x = SurveyReader(utils.path_to_text_fixture("hidden.xls"))
        x_results = x.to_json_dict()

        expected_dict = [{
            u'type': u'hidden',
            u'name': u'hidden_test'
        }, {
            'children': [{
                'bind': {
                    'calculate': "concat('uuid:', uuid())",
                    'readonly': 'true()'
                },
                'name': 'instanceID',
                'type': 'calculate'
            }],
            'control': {
                'bodyless': True
            },
            'name':
            'meta',
            'type':
            'group'
        }]
        self.assertEqual(x_results[u"children"], expected_dict)
コード例 #17
0
ファイル: builder_tests.py プロジェクト: mattlangeman/pyxform
 def test_new_widgets(self):
     survey = utils.build_survey('widgets.xls')
     path = utils.path_to_text_fixture('widgets.xml')
     survey.to_xml
     with open(path) as f:
         expected = etree.fromstring(survey.to_xml())
         result = etree.fromstring(f.read())
         self.assertTrue(xml_compare(expected, result))
コード例 #18
0
ファイル: test_area.py プロジェクト: charlesfleche/pyxform
    def test_create_from_path(self):
        path = utils.path_to_text_fixture("area.xlsx")
        survey = create_survey_from_path(path)
        path = os.path.join(
            os.path.dirname(__file__), 'test_expected_output', 'area.xml')

        with codecs.open(path, encoding='utf-8') as f:
            self.assertMultiLineEqual(survey.to_xml(), f.read())
コード例 #19
0
ファイル: builder_tests.py プロジェクト: Topol/pyxform
 def test_new_widgets(self):
     survey = utils.build_survey('widgets.xls')
     path = utils.path_to_text_fixture('widgets.xml')
     survey.to_xml
     with open(path) as f:
         expected = etree.fromstring(survey.to_xml())
         result = etree.fromstring(f.read())
         self.assertTrue(xml_compare(expected, result))
コード例 #20
0
 def runTest(self):
     
     path_to_excel_file = utils.path_to_text_fixture("warnings.xls")
     
     warnings = []
     xls2json.parse_file_to_json(path_to_excel_file, warnings=warnings)
     #print '\n'.join(warnings)
     self.assertEquals(len(warnings), 17, "Found " + str(len(warnings)) + " warnings")
コード例 #21
0
ファイル: xls2json_tests.py プロジェクト: bderenzi/pyxform
 def test_equivalency(self):
     equivalent_fixtures = [
         "group",
         "loop",  #'gps',
         "specify_other",
         "include",
         "text_and_integer",
         "include_json",
         "yes_or_no_question",
     ]
     for fixture in equivalent_fixtures:
         xls_path = utils.path_to_text_fixture("%s.xls" % fixture)
         csv_path = utils.path_to_text_fixture("%s.csv" % fixture)
         xls_inp = xls_to_dict(xls_path)
         csv_inp = csv_to_dict(csv_path)
         self.maxDiff = None
         self.assertEqual(csv_inp, xls_inp)
コード例 #22
0
 def test_a_unicode_csv_works(self):
     """
     Simply tests that xls2json_backends.csv_to_dict does not have a problem
     with a csv with unicode characters
     """
     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))
コード例 #23
0
ファイル: xls2json_tests.py プロジェクト: nathanathan/pyxform
 def test_a_unicode_csv_works(self):
     """
     Simply tests that xls2json_backends.csv_to_dict does not have a problem
     with a csv with unicode characters
     """
     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))
コード例 #24
0
ファイル: loop_tests.py プロジェクト: Topol/pyxform
 def test_for_loop(self):
     path = utils.path_to_text_fixture('for_loop.xls')
     survey = create_survey_from_xls(path)
     self.maxDiff = None
     try:
         actual_xml = survey.to_xml()
     except ValidationError:
         self.fail("survey.to_xml() raised ValidationError.")
コード例 #25
0
ファイル: loop_tests.py プロジェクト: mattlangeman/pyxform
 def test_for_loop(self):
     path = utils.path_to_text_fixture('for_loop.xls')
     survey = create_survey_from_xls(path)
     self.maxDiff = None
     try:
         actual_xml = survey.to_xml()
     except ValidationError:
         self.fail("survey.to_xml() raised ValidationError.")
コード例 #26
0
ファイル: xls2json_tests.py プロジェクト: bderenzi/pyxform
    def test_text_and_integer(self):
        x = SurveyReader(utils.path_to_text_fixture("text_and_integer.xls"))

        expected_dict = [
            {u"text": {u"english": u"What is your name?"}, u"type": u"text", u"name": u"your_name"},
            {u"text": {u"english": u"How many years old are you?"}, u"type": u"integer", u"name": u"your_age"},
        ]

        self.assertEqual(x.to_json_dict()[u"children"], expected_dict)
コード例 #27
0
ファイル: builder_tests.py プロジェクト: reyrodrigues/pyxform
 def setUp(self):
     self.this_directory = os.path.dirname(__file__)
     survey_out = Survey(name=u"age", sms_keyword=u"age", type=u"survey")
     question = InputQuestion(name=u"age")
     question.type = u"integer"
     question.label = u"How old are you?"
     survey_out.add_child(question)
     self.survey_out_dict = survey_out.to_json_dict()
     print_pyobj_to_json(self.survey_out_dict, utils.path_to_text_fixture("how_old_are_you.json"))
コード例 #28
0
ファイル: builder_tests.py プロジェクト: mattlangeman/pyxform
 def setUp(self):
     self.this_directory = os.path.dirname(__file__)
     survey_out = Survey(name=u"age", type=u"survey")
     question = InputQuestion(name=u"age")
     question.type = u"integer"
     question.label = u"How old are you?"
     survey_out.add_child(question)
     self.survey_out_dict = survey_out.to_json_dict()
     print_pyobj_to_json(self.survey_out_dict,
                         utils.path_to_text_fixture("how_old_are_you.json"))
コード例 #29
0
    def test_gps(self):
        x = SurveyReader(utils.path_to_text_fixture("gps.xls"))

        expected_dict = [{
            u'type': u'gps',
            u'name': u'location',
            u'label': u'GPS'
        }]

        self.assertEqual(x.to_json_dict()[u"children"], expected_dict)
コード例 #30
0
    def runTest(self):
       
        path_to_excel_file = utils.path_to_text_fixture("xlsform_spec_test.xls")
        
        #Get the xform output path:
        directory, filename = os.path.split(path_to_excel_file)
        root_filename, ext = os.path.splitext(filename)
        path_to_xform = os.path.join(directory, root_filename + ".xml")

        #Do the conversion:
        json_survey = xls2json.parse_file_to_json(path_to_excel_file)
        survey = pyxform.create_survey_element_from_dict(json_survey)
        survey.print_xform_to_file(path_to_xform)
        
        #Compare with the expected output:
        expected_path = utils.path_to_text_fixture("spec_test_expected_output.xml")
        with codecs.open(expected_path, 'rb', encoding="utf-8") as expected_file:
            expected = etree.fromstring(expected_file.read())
            result = etree.fromstring(survey.to_xml())
            self.assertTrue(xml_compare(expected, result))
コード例 #31
0
 def test_json(self):
     x = SurveyReader(utils.path_to_text_fixture("group.xls"))
     x_results = x.to_json_dict()
     expected_dict = {
         u'name': u'group',
         u'title': u'group',
         u'id_string': u'group',
         u'sms_keyword': u'group',
         u'default_language': u'default',
         u'type': u'survey',
         u'children': [
             {
                 u'name': u'family_name',
                 u'type': u'text',
                 u'label': {u'English': u"What's your family name?"}
                 },
             {
                 u'name': u'father',
                 u'type': u'group',
                 u'label': {u'English': u'Father'},
                 u'children': [
                     {
                         u'name': u'phone_number',
                         u'type': u'phone number',
                         u'label': {u'English': u"What's your father's phone number?"}
                         },
                     {
                         u'name': u'age',
                         u'type': u'integer',
                         u'label': {u'English': u'How old is your father?'}
                         }
                     ],
                 },
             {
                 u'children': [
                     {
                         u'bind': {
                             'calculate': "concat('uuid:', uuid())",
                             'readonly': 'true()'
                         },
                         u'name': 'instanceID',
                         u'type': 'calculate'
                     }
                 ],
                 u'control': {
                     'bodyless': True
                 },
                 u'name': 'meta',
                 u'type': u'group'
             }
             ],
         }
     self.maxDiff = None
     self.assertEqual(x_results, expected_dict)
コード例 #32
0
ファイル: xls2json_tests.py プロジェクト: Topol/pyxform
    def test_hidden(self):
        x = SurveyReader(utils.path_to_text_fixture("hidden.xls"))
        x_results = x.to_json_dict()

        expected_dict = [
            {
                u'type': u'hidden',
                u'name': u'hidden_test',
                }
        ]
        self.assertEqual(x_results[u"children"], expected_dict)
コード例 #33
0
    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)
コード例 #34
0
    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)
コード例 #35
0
    def test_equality_of_to_dict(self):
        x = SurveyReader(utils.path_to_text_fixture("group.xls"))
        x_results = x.to_json_dict()

        survey = create_survey_element_from_dict(x_results)
        survey_dict = survey.to_json_dict()
        # using the builder sets the title attribute to equal name
        # this won't happen through reading the excel file as done by
        # SurveyReader.
        # Now it happens.
        #del survey_dict[u'title']
        self.maxDiff = None
        self.assertEqual(x_results, survey_dict)
コード例 #36
0
ファイル: group_test.py プロジェクト: Topol/pyxform
    def test_equality_of_to_dict(self):
        x = SurveyReader(utils.path_to_text_fixture("group.xls"))
        x_results = x.to_json_dict()

        survey = create_survey_element_from_dict(x_results)
        survey_dict = survey.to_json_dict()
        # using the builder sets the title attribute to equal name
        # this won't happen through reading the excel file as done by
        # SurveyReader.
        # Now it happens.
        #del survey_dict[u'title']
        self.maxDiff = None
        self.assertEqual(x_results, survey_dict)
コード例 #37
0
ファイル: xls2json_tests.py プロジェクト: bderenzi/pyxform
    def test_simple_yes_or_no_question(self):
        x = SurveyReader(utils.path_to_text_fixture("yes_or_no_question.xls"))
        x_results = x.to_json_dict()

        expected_dict = [
            {
                u"label": {u"english": u"have you had a good day today?"},
                u"type": u"select one",
                u"name": u"good_day",
                u"choices": [
                    {u"label": {u"english": u"yes"}, u"name": u"yes"},
                    {u"label": {u"english": u"no"}, u"name": u"no"},
                ],
            }
        ]
        self.assertEqual(x_results[u"children"], expected_dict)
コード例 #38
0
    def test_text_and_integer(self):
        x = SurveyReader(utils.path_to_text_fixture("text_and_integer.xls"))

        expected_dict = [{
            u'text': {
                u'english': u'What is your name?'
            },
            u'type': u'text',
            u'name': u'your_name'
        }, {
            u'text': {
                u'english': u'How many years old are you?'
            },
            u'type': u'integer',
            u'name': u'your_age'
        }]

        self.assertEqual(x.to_json_dict()[u"children"], expected_dict)
コード例 #39
0
    def test_table(self):
        x = SurveyReader(utils.path_to_text_fixture("simple_loop.xls"))

        expected_dict = {
            u'type':
            u'survey',
            u'name':
            u'simple_loop',
            u'id_string':
            u'simple_loop',
            u'default_language':
            u'default',
            u'title':
            u'simple_loop',
            u'children': [{
                u'children': [{
                    u'type': u'integer',
                    u'name': u'count',
                    u'label': {
                        u'English': u'How many are there in this group?'
                    }
                }],
                u'type':
                u'loop',
                u'name':
                u'my_table',
                u'columns': [{
                    u'name': u'col1',
                    u'label': {
                        u'English': u'Column 1'
                    }
                }, {
                    u'name': u'col2',
                    u'label': {
                        u'English': u'Column 2'
                    }
                }],
                u'label': {
                    u'English': u'My Table'
                }
            }]
        }
        self.maxDiff = None
        self.assertEqual(x.to_json_dict(), expected_dict)
コード例 #40
0
ファイル: xls2json_tests.py プロジェクト: nathanathan/pyxform
    def test_hidden(self):
        x = SurveyReader(utils.path_to_text_fixture("hidden.xls"))
        x_results = x.to_json_dict()

        expected_dict = [
            {u"type": u"hidden", u"name": u"hidden_test"},
            {
                "children": [
                    {
                        "bind": {"calculate": "concat('uuid:', uuid())", "readonly": "true()"},
                        "name": "instanceID",
                        "type": "calculate",
                    }
                ],
                "control": {"bodyless": True},
                "name": "meta",
                "type": "group",
            },
        ]
        self.assertEqual(x_results[u"children"], expected_dict)
コード例 #41
0
ファイル: xls2json_tests.py プロジェクト: nathanathan/pyxform
    def test_gps(self):
        x = SurveyReader(utils.path_to_text_fixture("gps.xls"))

        expected_dict = [
            {u"type": u"gps", u"name": u"location", u"label": u"GPS"},
            {
                "children": [
                    {
                        "bind": {"calculate": "concat('uuid:', uuid())", "readonly": "true()"},
                        "name": "instanceID",
                        "type": "calculate",
                    }
                ],
                "control": {"bodyless": True},
                "name": "meta",
                "type": "group",
            },
        ]

        self.assertEqual(x.to_json_dict()[u"children"], expected_dict)
コード例 #42
0
ファイル: xls2json_tests.py プロジェクト: nathanathan/pyxform
    def test_text_and_integer(self):
        x = SurveyReader(utils.path_to_text_fixture("text_and_integer.xls"))

        expected_dict = [
            {u"label": {u"english": u"What is your name?"}, u"type": u"text", u"name": u"your_name"},
            {u"label": {u"english": u"How many years old are you?"}, u"type": u"integer", u"name": u"your_age"},
            {
                u"children": [
                    {
                        u"bind": {"calculate": "concat('uuid:', uuid())", "readonly": "true()"},
                        u"name": "instanceID",
                        u"type": "calculate",
                    }
                ],
                u"control": {"bodyless": True},
                u"name": "meta",
                u"type": u"group",
            },
        ]

        self.assertEqual(x.to_json_dict()[u"children"], expected_dict)
コード例 #43
0
ファイル: xls2json_tests.py プロジェクト: Topol/pyxform
    def test_simple_yes_or_no_question(self):
        x = SurveyReader(utils.path_to_text_fixture("yes_or_no_question.xls"))
        x_results = x.to_json_dict()

        expected_dict = [
            {
                u'label': {u'english': u'have you had a good day today?'},
                u'type': u'select one',
                u'name': u'good_day',
                u'choices': [
                    {
                        u'label': {u'english': u'yes'},
                        u'name': u'yes'
                        },
                    {
                        u'label': {u'english': u'no'},
                        u'name': u'no'
                        }
                    ]
                }
            ]
        self.assertEqual(x_results[u"children"], expected_dict)
コード例 #44
0
    def test_text_and_integer(self):
        x = SurveyReader(utils.path_to_text_fixture("text_and_integer.xls"))

        expected_dict = [
            {
                u'label': {
                    u'english': u'What is your name?'
                },
                u'type': u'text',
                u'name': u'your_name'
            },
            {
                u'label': {
                    u'english': u'How many years old are you?'
                },
                u'type': u'integer',
                u'name': u'your_age'
            },
            {
                u'children': [
                    {
                        u'bind': {
                            'calculate': "concat('uuid:', uuid())",
                            'readonly': 'true()'
                        },
                        u'name': 'instanceID',
                        u'type': 'calculate'
                    }
                ],
                u'control': {
                    'bodyless': True
                },
                u'name': 'meta',
                u'type': u'group'
            }
        ]

        self.assertEqual(x.to_json_dict()[u"children"], expected_dict)
コード例 #45
0
ファイル: tests_by_file.py プロジェクト: saeemarif/pyxform
    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)
            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())
                reporter = lambda x: sys.stdout.write(x + "\n") 
                self.assertTrue(xml_compare(expected, result, reporter=reporter))
            os.remove(path_to_output_xform)
コード例 #46
0
ファイル: builder_tests.py プロジェクト: mattlangeman/pyxform
 def test_create_from_file_object(self):
     path = utils.path_to_text_fixture('yes_or_no_question.xls')
     with open(path) as f:
         s = create_survey_from_xls(f)
コード例 #47
0
 def setUp(self):
     self.survey = create_survey_from_xls(
         utils.path_to_text_fixture("yes_or_no_question.xls"))
コード例 #48
0
 def test_loop(self):
     path = utils.path_to_text_fixture('another_loop.xls')
     survey = create_survey_from_xls(path)
     self.maxDiff = None
     expected_dict = {
         u'name':
         u'another_loop',
         u'id_string':
         u'another_loop',
         u'sms_keyword':
         u'another_loop',
         u'default_language':
         u'default',
         u'title':
         u'another_loop',
         u'type':
         u'survey',
         u'children': [{
             u'name':
             u'loop_vehicle_types',
             u'type':
             u'group',
             u'children': [{
                 u'label': {
                     u'English': u'Car',
                     u'French': u'Voiture'
                 },
                 u'name':
                 u'car',
                 u'type':
                 u'group',
                 u'children': [{
                     u'label': {
                         u'English': u'How many do you have?',
                         u'French': u'Combien avoir?'
                     },
                     u'name': u'total',
                     u'type': u'integer'
                 }, {
                     u'bind': {
                         u'constraint': u'. <= ../total'
                     },
                     u'label': {
                         u'English': u'How many are working?',
                         u'French': u'Combien marcher?'
                     },
                     u'name': u'working',
                     u'type': u'integer'
                 }],
             }, {
                 u'label': {
                     u'English': u'Motorcycle',
                     u'French': u'Moto'
                 },
                 u'name':
                 u'motor_cycle',
                 u'type':
                 u'group',
                 u'children': [{
                     u'label': {
                         u'English': u'How many do you have?',
                         u'French': u'Combien avoir?'
                     },
                     u'name': u'total',
                     u'type': u'integer'
                 }, {
                     u'bind': {
                         u'constraint': u'. <= ../total'
                     },
                     u'label': {
                         u'English': u'How many are working?',
                         u'French': u'Combien marcher?'
                     },
                     u'name': u'working',
                     u'type': u'integer'
                 }],
             }]
         }, {
             u'children': [{
                 u'bind': {
                     'calculate': "concat('uuid:', uuid())",
                     'readonly': 'true()'
                 },
                 u'name': 'instanceID',
                 u'type': 'calculate'
             }],
             u'control': {
                 'bodyless': True
             },
             u'name':
             'meta',
             u'type':
             u'group'
         }],
     }
     self.assertEquals(survey.to_json_dict(), expected_dict)
コード例 #49
0
ファイル: loop_tests.py プロジェクト: mattlangeman/pyxform
 def test_loop(self):
     path = utils.path_to_text_fixture('another_loop.xls')
     survey = create_survey_from_xls(path)
     self.maxDiff = None
     expected_dict = {
         u'name':
         u'another_loop',
         u'id_string':
         u'another_loop',
         u'default_language':
         u'default',
         u'title':
         u'another_loop',
         u'type':
         u'survey',
         u'children': [{
             u'label': {
                 u'English': u'Car',
                 u'French': u'Voiture'
             },
             u'name':
             u'car',
             u'type':
             u'group',
             u'children': [{
                 u'label': {
                     u'English': u'How many do you have?',
                     u'French': u'Combien avoir?'
                 },
                 u'name': u'total',
                 u'type': u'integer'
             }, {
                 u'bind': {
                     u'constraint': u'. <= ../total'
                 },
                 u'label': {
                     u'English': u'How many are working?',
                     u'French': u'Combien marcher?'
                 },
                 u'name': u'working',
                 u'type': u'integer'
             }],
         }, {
             u'label': {
                 u'English': u'Motorcycle',
                 u'French': u'Moto'
             },
             u'name':
             u'motor_cycle',
             u'type':
             u'group',
             u'children': [{
                 u'label': {
                     u'English': u'How many do you have?',
                     u'French': u'Combien avoir?'
                 },
                 u'name': u'total',
                 u'type': u'integer'
             }, {
                 u'bind': {
                     u'constraint': u'. <= ../total'
                 },
                 u'label': {
                     u'English': u'How many are working?',
                     u'French': u'Combien marcher?'
                 },
                 u'name': u'working',
                 u'type': u'integer'
             }],
         }],
     }
     self.assertEquals(survey.to_json_dict(), expected_dict)
コード例 #50
0
ファイル: builder_tests.py プロジェクト: SEL-Columbia/pyxform
 def tearDown(self):
     import os
     os.remove(utils.path_to_text_fixture("how_old_are_you.json"))
コード例 #51
0
ファイル: builder_tests.py プロジェクト: SEL-Columbia/pyxform
 def test_create_from_file_object(self):
     path = utils.path_to_text_fixture('yes_or_no_question.xls')
     with open(path) as f:
         create_survey_from_xls(f)
コード例 #52
0
ファイル: builder_tests.py プロジェクト: mattlangeman/pyxform
 def tearDown(self):
     import os
     os.remove(utils.path_to_text_fixture("how_old_are_you.json"))
コード例 #53
0
 def load_xlsx_file():
     x = SurveyReader(
         utils.path_to_text_fixture("text_and_integer_xlsx.xlsx"))
コード例 #54
0
 def setUp(self):
     self.path = utils.path_to_text_fixture("settings.xls")