本文整理汇总了Python中pyxform.xls2json.SurveyReader类的典型用法代码示例。如果您正苦于以下问题:Python SurveyReader类的具体用法?Python SurveyReader怎么用?Python SurveyReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SurveyReader类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:flipside-org,项目名称:pyxform,代码行数:28,代码来源:xls2json_tests.py
示例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)
开发者ID:aptivate,项目名称:pyxform,代码行数:31,代码来源:xls2json_tests.py
示例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)
开发者ID:XLSForm,项目名称:pyxform,代码行数:7,代码来源:bug_tests.py
示例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)
开发者ID:bderenzi,项目名称:pyxform,代码行数:30,代码来源:xls2json_tests.py
示例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)
开发者ID:XLSForm,项目名称:pyxform,代码行数:32,代码来源:xls2json_tests.py
示例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
开发者ID:lindsay-stevens,项目名称:pyxform,代码行数:7,代码来源:builder.py
示例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)
开发者ID:aptivate,项目名称:pyxform,代码行数:35,代码来源:builder_tests.py
示例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)
开发者ID:Topol,项目名称:pyxform,代码行数:34,代码来源:xls2json_tests.py
示例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])
开发者ID:aptivate,项目名称:pyxform,代码行数:7,代码来源:builder_tests.py
示例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)
开发者ID:aptivate,项目名称:pyxform,代码行数:29,代码来源:builder_tests.py
示例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)
开发者ID:flipside-org,项目名称:pyxform,代码行数:25,代码来源:xls2json_tests.py
示例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)
开发者ID:aptivate,项目名称:pyxform,代码行数:32,代码来源:group_test.py
示例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)
开发者ID:bderenzi,项目名称:pyxform,代码行数:9,代码来源:xls2json_tests.py
示例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)
开发者ID:Topol,项目名称:pyxform,代码行数:11,代码来源:xls2json_tests.py
示例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)
开发者ID:SEL-Columbia,项目名称:pyxform,代码行数:54,代码来源:group_test.py
示例16: process_xls_io_to_section_json
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,代码行数:12,代码来源:views.py
示例17: test_json
def test_json(self):
x = SurveyReader(utils.path_to_text_fixture("group.xls"))
x_results = x.to_json_dict()
expected_dict = {
"name": "group",
"title": "group",
"id_string": "group",
"sms_keyword": "group",
"default_language": "default",
"type": "survey",
"children": [
{
"name": "family_name",
"type": "text",
"label": {"English": "What's your family name?"},
},
{
"name": "father",
"type": "group",
"label": {"English": "Father"},
"children": [
{
"name": "phone_number",
"type": "phone number",
"label": {"English": "What's your father's phone number?"},
},
{
"name": "age",
"type": "integer",
"label": {"English": "How old is your father?"},
},
],
},
{
"children": [
{
"bind": {
"calculate": "concat('uuid:', uuid())",
"readonly": "true()",
},
"name": "instanceID",
"type": "calculate",
}
],
"control": {"bodyless": True},
"name": "meta",
"type": "group",
},
],
}
self.maxDiff = None
self.assertEqual(x_results, expected_dict)
开发者ID:XLSForm,项目名称:pyxform,代码行数:52,代码来源:group_test.py
示例18: test_equality_of_to_dict
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)
开发者ID:Topol,项目名称:pyxform,代码行数:13,代码来源:group_test.py
示例19: load_file_to_dict
def load_file_to_dict(path):
"""
Takes a file path and loads it into a nested json dict
following the format in json_form_schema.json
The file may be a xls file or json file.
If it is xls it is converted using xls2json.
"""
if path.endswith(".json"):
name = _section_name(path)
return name, utils.get_pyobj_from_json(path)
else:
name = _section_name(path)
excel_reader = SurveyReader(path)
return name, excel_reader.to_json_dict()
开发者ID:XLSForm,项目名称:pyxform,代码行数:14,代码来源:file_utils.py
示例20: test_simple_yes_or_no_question
def test_simple_yes_or_no_question(self):
filename = "yes_or_no_question.xls"
path_to_excel_file = os.path.join(DIR, "example_xls", filename)
#Get the xform output path:
root_filename, ext = os.path.splitext(filename)
output_path = os.path.join(DIR, "test_output", root_filename + ".json")
expected_output_path = os.path.join(DIR, "test_expected_output", root_filename + ".json")
x = SurveyReader(path_to_excel_file)
x_results = x.to_json_dict()
with codecs.open(output_path, mode="w", encoding="utf-8") as fp:
json.dump(x_results, fp=fp, ensure_ascii=False, indent=4)
#Compare with the expected output:
with codecs.open(expected_output_path, 'rb', encoding="utf-8") as expected_file:
with codecs.open(output_path, 'rb', encoding="utf-8") as actual_file:
self.assertMultiLineEqual(expected_file.read(), actual_file.read())
开发者ID:flipside-org,项目名称:pyxform,代码行数:15,代码来源:xls2json_tests.py
注:本文中的pyxform.xls2json.SurveyReader类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论