本文整理匯總了Python中pyxform.xls2json.SurveyReader類的典型用法代碼示例。如果您正苦於以下問題:Python SurveyReader類的具體用法?Python SurveyReader怎麽用?Python SurveyReader使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了SurveyReader類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_hidden
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)
示例2: test_table
def test_table(self):
x = SurveyReader(absolute_path(__file__, "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)
示例3: test_xl_date_ambigous
def test_xl_date_ambigous(self):
"""Test non standard sheet with exception is processed successfully."""
filename = "xl_date_ambiguous.xlsx"
path_to_excel_file = os.path.join(DIR, "bug_example_xls", filename)
xls_reader = SurveyReader(path_to_excel_file)
survey_dict = xls_reader.to_json_dict()
self.assertTrue(len(survey_dict) > 0)
示例4: test_table
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)
示例5: test_text_and_integer
def test_text_and_integer(self):
x = SurveyReader(utils.path_to_text_fixture("text_and_integer.xls"))
expected_dict = [
{
"label": {"english": "What is your name?"},
"type": "text",
"name": "your_name",
},
{
"label": {"english": "How many years old are you?"},
"type": "integer",
"name": "your_age",
},
{
"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()["children"], expected_dict)
示例6: create_survey_from_xls
def create_survey_from_xls(path_or_file):
excel_reader = SurveyReader(path_or_file)
d = excel_reader.to_json_dict()
survey = create_survey_element_from_dict(d)
if not survey.id_string:
survey.id_string = excel_reader._name
return survey
示例7: test_specify_other
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)
示例8: test_table
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)
示例9: test_include_json
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])
示例10: test_include
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)
示例11: test_gps
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)
示例12: test_json
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)
示例13: test_text_and_integer
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)
示例14: test_hidden
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)
示例15: test_json
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)