本文整理匯總了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)
示例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)
示例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)
示例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])
示例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)
示例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)
示例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)
示例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)
示例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())
示例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)
示例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)
示例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)
示例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())
示例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)