示例#1
0
    def __init__(self, cid_path=None):
        """
        Initialize a new CID with :py:attr:`~cutplace.interface.Cid.location`
        pointing to ``cid_path``, which can be one of the following:

        * a path to a file using CSV, Excel, or ODS as format; for CSV files,
          the delimiter is assumed to be a comma (,) and the encoding to be
          UTF-8 (which is backward compatible with ASCII).
        * ``None``, in which case location is automatically set to
          :py:func:`cutplace.errors.create_caller_location`.
        * an :py:class:`io.StringIO` containing a CSV
        """
        self._cid_path = cid_path
        self._data_format = None
        self._field_names = []
        self._field_formats = []
        self._field_name_to_format_map = {}
        self._field_name_to_index_map = {}
        self._check_names = []
        # TODO: Change to tuple(check_name, check).
        self._check_name_to_check_map = {}
        self._location = None
        self._check_name_to_class_map = Cid._create_name_to_class_map(
            checks.AbstractCheck)
        self._field_format_name_to_class_map = Cid._create_name_to_class_map(
            fields.AbstractFieldFormat)
        if cid_path is not None:
            self.read(cid_path, rowio.auto_rows(cid_path))
        else:
            self.set_location_to_caller()
示例#2
0
    def __init__(self, cid_path=None):
        """
        Initialize a new CID with :py:attr:`~cutplace.interface.Cid.location`
        pointing to ``cid_path``, which can be one of the following:

        * a path to a file using CSV, Excel, or ODS as format; for CSV files,
          the delimiter is assumed to be a comma (,) and the encoding to be
          UTF-8 (which is backward compatible with ASCII).
        * ``None``, in which case location is automatically set to
          :py:func:`cutplace.errors.create_caller_location`.
        * an :py:class:`io.StringIO` containing a CSV
        """
        self._cid_path = cid_path
        self._data_format = None
        self._field_names = []
        self._field_formats = []
        self._field_name_to_format_map = {}
        self._field_name_to_index_map = {}
        self._check_names = []
        # TODO: Change to tuple(check_name, check).
        self._check_name_to_check_map = {}
        self._location = None
        self._check_name_to_class_map = Cid._create_name_to_class_map(checks.AbstractCheck)
        self._field_format_name_to_class_map = Cid._create_name_to_class_map(fields.AbstractFieldFormat)
        if cid_path is not None:
            self.read(cid_path, rowio.auto_rows(cid_path))
        else:
            self.set_location_to_caller()
示例#3
0
 def set_cid_from_path(self, cid_path):
     """
     Read the :py:class:`cutplace.interface.Cid` to be used by this
     application from ``cid_path``.
     """
     assert cid_path is not None
     new_cid = interface.Cid()
     _log.info('read CID from "%s"', cid_path)
     cid_rows = rowio.auto_rows(cid_path)
     new_cid.read(cid_path, cid_rows)
     self.cid = new_cid
     self.cid_path = cid_path
示例#4
0
 def set_cid_from_path(self, cid_path):
     """
     Read the :py:class:`cutplace.interface.Cid` to be used by this
     application from ``cid_path``.
     """
     assert cid_path is not None
     new_cid = interface.Cid()
     _log.info('read CID from "%s"', cid_path)
     cid_rows = rowio.auto_rows(cid_path)
     new_cid.read(cid_path, cid_rows)
     self.cid = new_cid
     self.cid_path = cid_path
示例#5
0
 def test_can_auto_read_ods_rows(self):
     ods_path = dev_test.path_to_test_data('valid_customers.ods')
     self._assert_rows_contain_data(rowio.auto_rows(ods_path))
示例#6
0
 def test_can_auto_read_excel_rows(self):
     excel_path = dev_test.path_to_test_data('valid_customers.xls')
     self._assert_rows_contain_data(rowio.auto_rows(excel_path))