當前位置: 首頁>>代碼示例>>Python>>正文


Python SurveyReader.to_dict方法代碼示例

本文整理匯總了Python中pyxform.xls2json.SurveyReader.to_dict方法的典型用法代碼示例。如果您正苦於以下問題:Python SurveyReader.to_dict方法的具體用法?Python SurveyReader.to_dict怎麽用?Python SurveyReader.to_dict使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pyxform.xls2json.SurveyReader的用法示例。


在下文中一共展示了SurveyReader.to_dict方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_json

# 需要導入模塊: from pyxform.xls2json import SurveyReader [as 別名]
# 或者: from pyxform.xls2json.SurveyReader import to_dict [as 別名]
 def test_json(self):
     x = SurveyReader("pyxform/tests/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)
開發者ID:aptivate,項目名稱:pyxform,代碼行數:34,代碼來源:group_test.py

示例2: test_specify_other

# 需要導入模塊: from pyxform.xls2json import SurveyReader [as 別名]
# 或者: from pyxform.xls2json.SurveyReader import to_dict [as 別名]
 def test_specify_other(self):
     excel_reader = SurveyReader("pyxform/tests/specify_other.xls")
     d = excel_reader.to_dict()
     survey = create_survey_element_from_dict(d)
     expected_dict = {
         u'name': 'specify_other',
         u'type': u'survey',
         u'children': [
             {
                 u'name': u'sex',
                 u'label': {u'English': u'What sex are you?'},
                 u'type': u'select one',
                 u'children': [
                     {
                         u'name': u'male',
                         u'label': {u'English': u'Male'}
                         },
                     {
                         u'name': u'female',
                         u'label': {u'English': u'Female'}
                         },
                     {
                         u'name': u'other',
                         u'label': u'Other'
                         }
                     ]
                 },
             {
                 u'name': u'sex_other',
                 u'bind': {u'relevant': u"selected(../sex, 'other')"},
                 u'label': u'Specify other.',
                 u'type': u'text'}
             ]
         }
     self.assertEqual(survey.to_dict(), expected_dict)
開發者ID:aptivate,項目名稱:pyxform,代碼行數:37,代碼來源:builder_tests.py

示例3: test_table

# 需要導入模塊: from pyxform.xls2json import SurveyReader [as 別名]
# 或者: from pyxform.xls2json.SurveyReader import to_dict [as 別名]
    def test_table(self):
        x = SurveyReader(utils.path_to_text_fixture("simple_loop.xls"))

        expected_dict = {
            u'type': u'survey',
            u'name': '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.assertEqual(x.to_dict(), expected_dict)
開發者ID:ChandniD,項目名稱:pyxform,代碼行數:33,代碼來源:xls2json_tests.py

示例4: test_include_json

# 需要導入模塊: from pyxform.xls2json import SurveyReader [as 別名]
# 或者: from pyxform.xls2json.SurveyReader import to_dict [as 別名]
    def test_include_json(self):            
        excel_reader = SurveyReader("pyxform/tests/include_json.xls")
        d = excel_reader.to_dict()
        survey_in = create_survey_element_from_dict(d)

        for k, v in survey_in.to_dict().items():
            if k!="name": self.assertEqual(v, self.survey_out_dict[k])
開發者ID:aptivate,項目名稱:pyxform,代碼行數:9,代碼來源:builder_tests.py

示例5: test_include

# 需要導入模塊: from pyxform.xls2json import SurveyReader [as 別名]
# 或者: from pyxform.xls2json.SurveyReader import to_dict [as 別名]
    def test_include(self):
        excel_reader = SurveyReader("pyxform/tests/include.xls")
        d = excel_reader.to_dict()
        survey = create_survey_element_from_dict(d)
        expected_dict = {
            u'name': 'include',
            u'type': u'survey',
            u'children': [
                {
                    u'name': u'name',
                    u'label': {u'English': u"What's your name?"},
                    u'type': u'text'
                    },
                    {
                        u'name': u'good_day',
                        u'label': {u'english': u'have you had a good day today?'},
                        u'type': u'select one',
                        u'children': [
                            {
                                u'name': u'yes',
                                u'label': {u'english': u'yes'}
                                },
                            {
                                u'name': u'no',
                                u'label': {u'english': u'no'}
                                }
                            ]}]}

        self.assertEqual(survey.to_dict(), expected_dict)
開發者ID:aptivate,項目名稱:pyxform,代碼行數:31,代碼來源:builder_tests.py

示例6: process_xls_io_to_section_json

# 需要導入模塊: from pyxform.xls2json import SurveyReader [as 別名]
# 或者: from pyxform.xls2json.SurveyReader import to_dict [as 別名]
def process_xls_io_to_section_json(file_io):
    # I agree that this function is not pretty, but I don't think we
    # should move this into the model because I prefer to think of the
    # model as file-format independent.
    path = save_in_temp_dir(file_io)
    m = re.search(r'([^/]+).xls$', path)
    slug = m.group(1)
    xlr = SurveyReader(path)
    xls_vals = xlr.to_dict()
    qjson = json.dumps(xls_vals)
    os.remove(path)
    return (slug, qjson)
開發者ID:mdxs,項目名稱:xls2xform,代碼行數:14,代碼來源:views.py

示例7: setUp

# 需要導入模塊: from pyxform.xls2json import SurveyReader [as 別名]
# 或者: from pyxform.xls2json.SurveyReader import to_dict [as 別名]
 def setUp(self):
     self.excel_files = [
         "gps.xls",
         "include.xls",
         "specify_other.xls",
         "group.xls",
         "loop.xls",
         "text_and_integer.xls",
         # todo: this file uses json that was written in
         # builder_tests.py this needs to be fixed.
         # "include_json.xls",
         "simple_loop.xls",
         "yes_or_no_question.xls",
         ]
     self.surveys = {}
     for filename in self.excel_files:
         path = "pyxform/tests/%s" % filename
         excel_reader = SurveyReader(path)
         d = excel_reader.to_dict()
         self.surveys[filename] = create_survey_element_from_dict(d)
開發者ID:aptivate,項目名稱:pyxform,代碼行數:22,代碼來源:dump_and_load_tests.py

示例8: test_simple_yes_or_no_question

# 需要導入模塊: from pyxform.xls2json import SurveyReader [as 別名]
# 或者: from pyxform.xls2json.SurveyReader import to_dict [as 別名]
    def test_simple_yes_or_no_question(self):
        x = SurveyReader(utils.path_to_text_fixture("yes_or_no_question.xls"))
        x_results = x.to_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)
開發者ID:ChandniD,項目名稱:pyxform,代碼行數:24,代碼來源:xls2json_tests.py

示例9: test_equality_of_to_dict

# 需要導入模塊: from pyxform.xls2json import SurveyReader [as 別名]
# 或者: from pyxform.xls2json.SurveyReader import to_dict [as 別名]
    def test_equality_of_to_dict(self):
        x = SurveyReader("pyxform/tests/group.xls")
        x_results = x.to_dict()

        survey_object = create_survey_element_from_dict(x_results)
        self.assertEqual(x_results, survey_object.to_dict())
開發者ID:aptivate,項目名稱:pyxform,代碼行數:8,代碼來源:group_test.py

示例10: test_text_and_integer

# 需要導入模塊: from pyxform.xls2json import SurveyReader [as 別名]
# 或者: from pyxform.xls2json.SurveyReader import to_dict [as 別名]
    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_dict()[u"children"], expected_dict)
開發者ID:ChandniD,項目名稱:pyxform,代碼行數:8,代碼來源:xls2json_tests.py

示例11: test_gps

# 需要導入模塊: from pyxform.xls2json import SurveyReader [as 別名]
# 或者: from pyxform.xls2json.SurveyReader import to_dict [as 別名]
    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_dict()[u"children"], expected_dict)
開發者ID:ChandniD,項目名稱:pyxform,代碼行數:8,代碼來源:xls2json_tests.py

示例12: test_gps

# 需要導入模塊: from pyxform.xls2json import SurveyReader [as 別名]
# 或者: from pyxform.xls2json.SurveyReader import to_dict [as 別名]
    def test_gps(self):
        x = SurveyReader(absolute_path(__file__, "gps.xls"))

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

        self.assertEqual(x.to_dict()[u"children"], expected_dict)
開發者ID:aptivate,項目名稱:pyxform,代碼行數:8,代碼來源:xls2json_tests.py

示例13: test_equality_of_to_dict

# 需要導入模塊: from pyxform.xls2json import SurveyReader [as 別名]
# 或者: from pyxform.xls2json.SurveyReader import to_dict [as 別名]
    def test_equality_of_to_dict(self):
        x = SurveyReader(utils.path_to_text_fixture("group.xls"))
        x_results = x.to_dict()

        survey_object = create_survey_element_from_dict(x_results)
        self.assertEqual(x_results, survey_object.to_dict())
開發者ID:ChandniD,項目名稱:pyxform,代碼行數:8,代碼來源:group_test.py

示例14: test_loop

# 需要導入模塊: from pyxform.xls2json import SurveyReader [as 別名]
# 或者: from pyxform.xls2json.SurveyReader import to_dict [as 別名]
    def test_loop(self):
        excel_reader = SurveyReader("pyxform/tests/loop.xls")
        d = excel_reader.to_dict()
        survey = create_survey_element_from_dict(d)

        expected_dict = {
            u'name': 'loop',
            u'type': u'survey',
            u'children': [
                {
                    u'name': u'available_toilet_types',
                    u'label': {u'english': u'What type of toilets are on the premises?'},
                    u'type': u'select all that apply',
                    u'bind': {u'constraint': u"(.='none' or not(selected(., 'none')))"},
                    u'children': [
                        {
                            u'name': u'pit_latrine_with_slab',
                            u'label': {u'english': u'Pit latrine with slab'}
                            },
                        {
                            u'name': u'open_pit_latrine',
                            u'label': {u'english': u'Pit latrine without slab/open pit'}
                            },
                        {
                            u'name': u'bucket_system',
                            u'label': {u'english': u'Bucket system'}
                            },
                        {
                            u'name': u'none',
                            u'label': u'None',
                            },
                        {
                            u'name': u'other',
                            u'label': u'Other'
                            },
                        ]
                    },

                {
                    u'name': u'available_toilet_types_other',
                    u'bind': {u'relevant': u"selected(../available_toilet_types, 'other')"},
                    u'label': u'Specify other.',
                    u'type': u'text'
                    },
                {
                    u'name': u'pit_latrine_with_slab',
                    u'label': {u'english': u'Pit latrine with slab'},
                    u'type' : u'group',
                    u'children': [
                        {
                            u'name': u'number',
                            u'label': {u'english': u'How many Pit latrine with slab are on the premises?'},
                            u'type': u'integer'
                            }]},
                {
                    u'name': u'open_pit_latrine',
                    u'label': {u'english': u'Pit latrine without slab/open pit'},
                    u'type' : u'group',
                    u'children': [
                        {
                            u'name': u'number',
                            u'label': {u'english': u'How many Pit latrine without slab/open pit are on the premises?'},
                            u'type': u'integer'
                            }
                        ]
                    },
                {
                    u'name': u'bucket_system',
                    u'label': {u'english': u'Bucket system'},
                    u'type' : u'group',
                    u'children': [
                        {
                            u'name': u'number',
                            u'label': {u'english': u'How many Bucket system are on the premises?'},
                            u'type': u'integer'
                            }
                        ]
                    },
                {
                    u'name': u'other',
                    u'label': u'Other',
                    u'type' : u'group',
                    u'children': [{u'name': u'number', u'label': {u'english': u'How many Other are on the premises?'}, u'type': u'integer'}]}]}

        self.assertEqual(survey.to_dict(), expected_dict)
開發者ID:aptivate,項目名稱:pyxform,代碼行數:87,代碼來源:builder_tests.py


注:本文中的pyxform.xls2json.SurveyReader.to_dict方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。