# Path: pyxform/xls2json_backends.py
# def convert_file_to_csv_string(path):
#     """
#     This will open a csv or xls file and return a CSV in the format:
#         sheet_name1
#         ,col1,col2
#         ,r1c1,r1c2
#         ,r2c1,r2c2
#         sheet_name2
#         ,col1,col2
#         ,r1c1,r1c2
#         ,r2c1,r2c2
# 
#     Currently, it processes csv files and xls files to ensure consistent
#     csv delimiters, etc. for tests.
#     """
#     if path.endswith(".csv"):
#         imported_sheets = csv_to_dict(path)
#     else:
#         imported_sheets = xls_to_dict(path)
#     foo = StringIO(newline="")
#     writer = csv.writer(foo, delimiter=",", quotechar='"', quoting=csv.QUOTE_MINIMAL)
#     for sheet_name, rows in imported_sheets.items():
#         writer.writerow([sheet_name])
#         out_keys = []
#         out_rows = []
#         for row in rows:
#             out_row = []
#             for key in row.keys():
#                 if key not in out_keys:
#                     out_keys.append(key)
#             for out_key in out_keys:
#                 out_row.append(row.get(out_key, None))
#             out_rows.append(out_row)
#         writer.writerow([None] + out_keys)
#         for out_row in out_rows:
#             writer.writerow([None] + out_row)
#     return foo.getvalue()
# 
# Path: tests/utils.py
# def path_to_text_fixture(filename):
# def build_survey(filename):
# def create_survey_from_fixture(fixture_name, filetype="xls", include_directory=False):
# def prep_class_config(cls, test_dir="tests"):
# def prep_for_xml_contains(text: str) -> "Tuple[str]":
# def get_temp_file():
# def get_temp_dir():


from unittest import TestCase
from pyxform.xls2json_backends import convert_file_to_csv_string
from tests import utils
# -*- coding: utf-8 -*-
"""
Test xls2json_backends util functions.
"""



class BackendUtilsTests(TestCase):
    def test_xls_to_csv(self):
        specify_other_xls = utils.path_to_text_fixture("specify_other.xls")
        converted_xls = convert_file_to_csv_string(specify_other_xls)
        specify_other_csv = utils.path_to_text_fixture("specify_other.csv")

# Path: pyxform/xls2json_backends.py
# def convert_file_to_csv_string(path):
#     """
#     This will open a csv or xls file and return a CSV in the format:
#         sheet_name1
#         ,col1,col2
#         ,r1c1,r1c2
#         ,r2c1,r2c2
#         sheet_name2
#         ,col1,col2
#         ,r1c1,r1c2
#         ,r2c1,r2c2
# 
#     Currently, it processes csv files and xls files to ensure consistent
#     csv delimiters, etc. for tests.
#     """
#     if path.endswith(".csv"):
#         imported_sheets = csv_to_dict(path)
#     else:
#         imported_sheets = xls_to_dict(path)
#     foo = StringIO(newline="")
#     writer = csv.writer(foo, delimiter=",", quotechar='"', quoting=csv.QUOTE_MINIMAL)
#     for sheet_name, rows in imported_sheets.items():
#         writer.writerow([sheet_name])
#         out_keys = []
#         out_rows = []
#         for row in rows:
#             out_row = []
#             for key in row.keys():
#                 if key not in out_keys:
#                     out_keys.append(key)
#             for out_key in out_keys:
#                 out_row.append(row.get(out_key, None))
#             out_rows.append(out_row)
#         writer.writerow([None] + out_keys)
#         for out_row in out_rows:
#             writer.writerow([None] + out_row)
#     return foo.getvalue()
# 
# Path: tests/utils.py
# def path_to_text_fixture(filename):
# def build_survey(filename):
# def create_survey_from_fixture(fixture_name, filetype="xls", include_directory=False):
# def prep_class_config(cls, test_dir="tests"):
# def prep_for_xml_contains(text: str) -> "Tuple[str]":
# def get_temp_file():
# def get_temp_dir():


# Path: tests/file_utils_test.py
from unittest import TestCase
from pyxform.xls2json_backends import convert_file_to_csv_string
from tests import utils

# -*- coding: utf-8 -*-
"""
Test xls2json_backends util functions.
"""



class BackendUtilsTests(TestCase):
    def test_xls_to_csv(self):
        specify_other_xls = utils.path_to_text_fixture("specify_other.xls")
        converted_xls = convert_file_to_csv_string(specify_other_xls)
        specify_other_csv = utils.path_to_text_fixture("specify_other.csv")

        converted_csv = convert_file_to_csv_string(specify_other_csv)