A package useful for validating files.
In requirements.txt
file add the following line:
#requirements.txt
git+https://[email protected]/licenseware/lware-components-file_validators.git
#other modules
You can install from requirements.txt with pip3 install -r requirements.txt
Alternatively you can install it with the command bellow:
pip3 install git+https://[email protected]/licenseware/lware-components-file_validators.git
from file_validators import GeneralValidator, validate_filename
v = GeneralValidator(
input_object, # required: file path, string or stream of bytes
required_input_type, # required: 'excel', 'csv', 'txt', 'string', 'stream'
required_sheets = [], # sheets names list that needs to be found in 'excel'
required_columns = [], # columns names list that needs to be found in 'excel', 'csv'
text_contains_all = [], # text list that needs to be found in 'txt', 'string', 'stream'
text_contains_any = [], # text list that needs to be found in 'txt', 'string', 'stream'
min_rows_number = 0 # minimum rows needed for 'excel', 'csv'
header_starts_at = 0 # row number where the header with columns starts (count starts from 0)
buffer = 9000 # bytes to read from stream/file
)
if v.validate():
# other logic
#OR
res = v.validate(show_reason=True)
if res['status'] == 'success':
return res['message']
elif res['status'] == 'fail':
return res['message']
In case you need to add new functionality:
git clone
pipenv install
pipenv shell
pytest -v -s
orpytest
- test only one function:
pytest -v -s tests/test_file_name.py::test_function_name