Skip to content

Commit

Permalink
Merge 7e439c7 into 2e3b828
Browse files Browse the repository at this point in the history
  • Loading branch information
jcampbell committed Apr 23, 2019
2 parents 2e3b828 + 7e439c7 commit 7394872
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions great_expectations/data_asset/file_data_asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ def expect_file_hash_to_equal(self, value, hash_alg='md5', result_format=None,
return {"success":success}

@DataAsset.expectation(["minsize", "maxsize"])
def expect_file_size_to_be_between(self, minsize, maxsize, result_format=None,
def expect_file_size_to_be_between(self, minsize=0, maxsize=None, result_format=None,
include_config=False, catch_exceptions=None,
meta=None):

Expand Down Expand Up @@ -421,31 +421,39 @@ def expect_file_size_to_be_between(self, minsize, maxsize, result_format=None,
:ref:`include_config`, :ref:`catch_exceptions`, and :ref:`meta`.
"""

success = False
try:
size = os.path.getsize(self._path)
except OSError:
raise

if not isinstance(minsize,int):
if not float(minsize).is_integer():
raise TypeError('minsize must be an integer')

if not isinstance(maxsize,int):
if maxsize is not None and not float(maxsize).is_integer():
raise TypeError('maxsize must be an integer')

if minsize < 0:
raise ValueError('minsize must be greater than of equal to 0')

if maxsize < 0:
if maxsize is not None and maxsize < 0:
raise ValueError('maxsize must be greater than of equal to 0')

if minsize > maxsize:
if maxsize is not None and minsize > maxsize:
raise ValueError('maxsize must be greater than of equal to minsize')

if (size >= minsize) and (size <= maxsize):
if maxsize is None and size >= minsize:
success = True
elif (size >= minsize) and (size <= maxsize):
success = True
else:
success = False

return {"success":success}
return {
"success": success,
"details": {
"filesize": size
}
}

@DataAsset.expectation(["filepath"])
def expect_file_to_exist(self, filepath=None, result_format=None, include_config=False,
Expand Down

0 comments on commit 7394872

Please sign in to comment.