# Path: pyxform/xls2xform.py
# def _create_parser():
#     """
#     Parse command line arguments.
#     """
#     parser = argparse.ArgumentParser()
#     parser.add_argument(
#         "path_to_XLSForm",
#         help="Path to the Excel XLSX file with the XLSForm definition.",
#     )
#     parser.add_argument("output_path", help="Path to save the output to.", nargs="?")
#     parser.add_argument(
#         "--json",
#         action="store_true",
#         help="Capture everything and report in JSON format.",
#     )
#     parser.add_argument(
#         "--skip_validate",
#         action="store_false",
#         default=True,
#         help="Do not run any external validators on the output XForm XML. "
#         "Without this flag, ODK Validate is run by default for backwards "
#         "compatibility. Internal pyxform checks cannot be skipped.",
#     )
#     parser.add_argument(
#         "--odk_validate",
#         action="store_true",
#         default=False,
#         help="Run the ODK Validate XForm external validator.",
#     )
#     parser.add_argument(
#         "--enketo_validate",
#         action="store_true",
#         default=False,
#         help="Run the Enketo Validate XForm external validator.",
#     )
#     parser.add_argument(
#         "--pretty_print",
#         action="store_true",
#         default=False,
#         help="Print XML forms with collapsed whitespace instead of pretty-printed.",
#     )
#     return parser
# 
# def _validator_args_logic(args):
#     """
#     Implements logic for how validator arguments work in combination.
# 
#     As per: https://github.com/XLSForm/pyxform/pull/167#issuecomment-353382008
# 
#     **backwards-compatible**
#     `xls2xform.py myform --skip_validate`: no validators
#     `xls2xform.py myform`: ODK only
# 
#     **new**
#     `xls2xform.py myform --enketo_validate`: Enketo only
#     `xls2xform.py myform --odk_validate`: ODK only
#     `xls2xform.py myform --enketo_validate --odk_validate`: both
#     `xls2xform.py myform --enketo_validate --odk_validate --skip_validate`: no validators
#     """
#     if not args.skip_validate:
#         args.odk_validate = False
#         args.enketo_validate = False
#     elif args.skip_validate and not (args.odk_validate or args.enketo_validate):
#         args.odk_validate = True
#         args.enketo_validate = False
#     return args
# 
# def get_xml_path(path):
#     """
#     Returns the xform file path
# 
#     Generates an output path for the xform file from the given
#     xlsx input file path.
#     """
#     return splitext(path)[0] + ".xml"
# 
# def main_cli():
#     parser = _create_parser()
#     raw_args = parser.parse_args()
#     args = _validator_args_logic(args=raw_args)
# 
#     # auto generate an output path if one was not given
#     if args.output_path is None:
#         args.output_path = get_xml_path(args.path_to_XLSForm)
# 
#     if args.json:
#         # Store everything in a list just in case the user wants to output
#         # as a JSON encoded string.
#         response = {"code": None, "message": None, "warnings": []}
# 
#         try:
#             response["warnings"] = xls2xform_convert(
#                 xlsform_path=args.path_to_XLSForm,
#                 xform_path=args.output_path,
#                 validate=args.odk_validate,
#                 pretty_print=args.pretty_print,
#                 enketo=args.enketo_validate,
#             )
# 
#             response["code"] = 100
#             response["message"] = "Ok!"
# 
#             if response["warnings"]:
#                 response["code"] = 101
#                 response["message"] = "Ok with warnings."
# 
#         except Exception as e:
#             # Catch the exception by default.
#             response["code"] = 999
#             response["message"] = str(e)
# 
#         logger.info(json.dumps(response))
#     else:
#         try:
#             warnings = xls2xform_convert(
#                 xlsform_path=args.path_to_XLSForm,
#                 xform_path=args.output_path,
#                 validate=args.odk_validate,
#                 pretty_print=args.pretty_print,
#                 enketo=args.enketo_validate,
#             )
#         except EnvironmentError as e:
#             # Do not crash if 'java' not installed
#             logger.error(e)
#         except ODKValidateError as e:
#             # Remove output file if there is an error
#             os.remove(args.output_path)
#             logger.error(e)
#         else:
#             if len(warnings) > 0:
#                 logger.warning("Warnings:")
#             for w in warnings:
#                 logger.warning(w)
#             logger.info("Conversion complete!")
# 
# Path: tests/utils.py
# def path_to_text_fixture(filename):
#     return os.path.join(example_xls.PATH, filename)


import argparse
import logging
import pyxform
    import mock
from unittest import TestCase
from pyxform.xls2xform import (
    _create_parser,
    _validator_args_logic,
    get_xml_path,
    main_cli,
)
from tests.utils import path_to_text_fixture
    from unittest import mock
Test xls2xform module.
"""
# The Django application xls2xform uses the function
# pyxform.create_survey. We have a test here to make sure no one
# breaks that function.



try:
except ImportError:


class XLS2XFormTests(TestCase):
    survey_package = {
        "id_string": "test_2011_08_29b",
        "name_of_main_section": "gps",
        "sections": {
            "gps": {
                "children": [{"name": "location", "type": "gps"}],
                "name": "gps",
                "type": "survey",
            }
        },
        "title": "test",
    }
    survey = pyxform.create_survey(**survey_package)

    def test_create_parser_without_args(self):
        """Should exit when no args provided."""
        with self.assertRaises(SystemExit):

# Path: pyxform/xls2xform.py
# def _create_parser():
#     """
#     Parse command line arguments.
#     """
#     parser = argparse.ArgumentParser()
#     parser.add_argument(
#         "path_to_XLSForm",
#         help="Path to the Excel XLSX file with the XLSForm definition.",
#     )
#     parser.add_argument("output_path", help="Path to save the output to.", nargs="?")
#     parser.add_argument(
#         "--json",
#         action="store_true",
#         help="Capture everything and report in JSON format.",
#     )
#     parser.add_argument(
#         "--skip_validate",
#         action="store_false",
#         default=True,
#         help="Do not run any external validators on the output XForm XML. "
#         "Without this flag, ODK Validate is run by default for backwards "
#         "compatibility. Internal pyxform checks cannot be skipped.",
#     )
#     parser.add_argument(
#         "--odk_validate",
#         action="store_true",
#         default=False,
#         help="Run the ODK Validate XForm external validator.",
#     )
#     parser.add_argument(
#         "--enketo_validate",
#         action="store_true",
#         default=False,
#         help="Run the Enketo Validate XForm external validator.",
#     )
#     parser.add_argument(
#         "--pretty_print",
#         action="store_true",
#         default=False,
#         help="Print XML forms with collapsed whitespace instead of pretty-printed.",
#     )
#     return parser
# 
# def _validator_args_logic(args):
#     """
#     Implements logic for how validator arguments work in combination.
# 
#     As per: https://github.com/XLSForm/pyxform/pull/167#issuecomment-353382008
# 
#     **backwards-compatible**
#     `xls2xform.py myform --skip_validate`: no validators
#     `xls2xform.py myform`: ODK only
# 
#     **new**
#     `xls2xform.py myform --enketo_validate`: Enketo only
#     `xls2xform.py myform --odk_validate`: ODK only
#     `xls2xform.py myform --enketo_validate --odk_validate`: both
#     `xls2xform.py myform --enketo_validate --odk_validate --skip_validate`: no validators
#     """
#     if not args.skip_validate:
#         args.odk_validate = False
#         args.enketo_validate = False
#     elif args.skip_validate and not (args.odk_validate or args.enketo_validate):
#         args.odk_validate = True
#         args.enketo_validate = False
#     return args
# 
# def get_xml_path(path):
#     """
#     Returns the xform file path
# 
#     Generates an output path for the xform file from the given
#     xlsx input file path.
#     """
#     return splitext(path)[0] + ".xml"
# 
# def main_cli():
#     parser = _create_parser()
#     raw_args = parser.parse_args()
#     args = _validator_args_logic(args=raw_args)
# 
#     # auto generate an output path if one was not given
#     if args.output_path is None:
#         args.output_path = get_xml_path(args.path_to_XLSForm)
# 
#     if args.json:
#         # Store everything in a list just in case the user wants to output
#         # as a JSON encoded string.
#         response = {"code": None, "message": None, "warnings": []}
# 
#         try:
#             response["warnings"] = xls2xform_convert(
#                 xlsform_path=args.path_to_XLSForm,
#                 xform_path=args.output_path,
#                 validate=args.odk_validate,
#                 pretty_print=args.pretty_print,
#                 enketo=args.enketo_validate,
#             )
# 
#             response["code"] = 100
#             response["message"] = "Ok!"
# 
#             if response["warnings"]:
#                 response["code"] = 101
#                 response["message"] = "Ok with warnings."
# 
#         except Exception as e:
#             # Catch the exception by default.
#             response["code"] = 999
#             response["message"] = str(e)
# 
#         logger.info(json.dumps(response))
#     else:
#         try:
#             warnings = xls2xform_convert(
#                 xlsform_path=args.path_to_XLSForm,
#                 xform_path=args.output_path,
#                 validate=args.odk_validate,
#                 pretty_print=args.pretty_print,
#                 enketo=args.enketo_validate,
#             )
#         except EnvironmentError as e:
#             # Do not crash if 'java' not installed
#             logger.error(e)
#         except ODKValidateError as e:
#             # Remove output file if there is an error
#             os.remove(args.output_path)
#             logger.error(e)
#         else:
#             if len(warnings) > 0:
#                 logger.warning("Warnings:")
#             for w in warnings:
#                 logger.warning(w)
#             logger.info("Conversion complete!")
# 
# Path: tests/utils.py
# def path_to_text_fixture(filename):
#     return os.path.join(example_xls.PATH, filename)


# Path: tests/xls2xform_tests.py
import argparse
import logging
import pyxform
    import mock
from unittest import TestCase
from pyxform.xls2xform import (
    _create_parser,
    _validator_args_logic,
    get_xml_path,
    main_cli,
)
from tests.utils import path_to_text_fixture
    from unittest import mock

Test xls2xform module.
"""
# The Django application xls2xform uses the function
# pyxform.create_survey. We have a test here to make sure no one
# breaks that function.



try:
except ImportError:


class XLS2XFormTests(TestCase):
    survey_package = {
        "id_string": "test_2011_08_29b",
        "name_of_main_section": "gps",
        "sections": {
            "gps": {
                "children": [{"name": "location", "type": "gps"}],
                "name": "gps",
                "type": "survey",
            }
        },
        "title": "test",
    }
    survey = pyxform.create_survey(**survey_package)

    def test_create_parser_without_args(self):
        """Should exit when no args provided."""
        with self.assertRaises(SystemExit):

            _create_parser().parse_args([])