Skip to content

Commit

Permalink
Making collections calls compatible with python 3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
AdityaSavara committed Nov 1, 2020
1 parent 6fe1088 commit fe2a089
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions UnitTesterSG/UnitTesterSGFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def customCompare(firstInComparison,secondInComparison, relativeTolerance=None,
#If two variables are both strings, just simply compare them directly
if ((type(firstInComparison) != str) and (type(secondInComparison) != str)):
#checks to see if both variables are iterable and converts them into numpy arrays
if isinstance(firstInComparison,collections.Iterable) and isinstance(secondInComparison,collections.Iterable):
if isinstance(firstInComparison,collections.abc.Iterable) and isinstance(secondInComparison,collections.abc.Iterable):
try:
firstInComparisonArray = np.array(firstInComparison)
secondInComparisonArray = np.array(secondInComparison)
Expand Down Expand Up @@ -92,7 +92,7 @@ def customCompare(firstInComparison,secondInComparison, relativeTolerance=None,
return False
#checks to see if one, not both, of the variables are iterable
#this is for the case with one variable being other such as None
elif isinstance(firstInComparison,collections.Iterable) or isinstance(secondInComparison,collections.Iterable):
elif isinstance(firstInComparison,collections.abc.Iterable) or isinstance(secondInComparison,collections.abc.Iterable):
return False
else: #both of the variables are not iterable and are therefore also not strings
#if comparison can not run then types are probably different and returns false
Expand Down
16 changes: 8 additions & 8 deletions UnitTesterSG/nestedObjectsFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# and [1, 2, [3, 4, 5], 6] will give 21.
def sumNested(arr):
currentSum = 0
if isinstance(arr,collections.Iterable):
if isinstance(arr,collections.abc.Iterable):
for elem in arr:
returnSum = sumNested(elem)
currentSum = currentSum + returnSum
Expand All @@ -23,7 +23,7 @@ def sumNested(arr):
# and [1, 2, [3, 4, 5], 6] will give 21.
def sumNestedAbsValues(arrayOrNumber):
currentSum = 0
if isinstance(arrayOrNumber,collections.Iterable):
if isinstance(arrayOrNumber,collections.abc.Iterable):
for elem in arrayOrNumber:
returnSum = sumNestedAbsValues(elem)
currentSum = currentSum + returnSum
Expand All @@ -41,9 +41,9 @@ def sumNestedAbsValues(arrayOrNumber):
#[1,2] is iterable but neither 1 nor 2 are iterable so isNestedOrString will return false
#[1,[2,3]] is iterable, 1 is not iterable but [2,3] is so isNestedOrString will return true
def isNestedOrString(arr):
if isinstance(arr,collections.Iterable):
if isinstance(arr,collections.abc.Iterable):
for elem in arr:
if isinstance(elem,collections.Iterable):
if isinstance(elem,collections.abc.Iterable):
return True
#If it finishes the loop then it hasn't found a non-iterable object and is not nested
return False
Expand All @@ -60,7 +60,7 @@ def isNestedOrString(arr):
#we do allow approximate comparisons using the variables relativeTolerance and absoluteTolerance
'''
def subtractNested(arr1,arr2,subtractionResult, relativeTolerance=None, absoluteTolerance=None, softStringCompare=False):
if isinstance(arr1,collections.Iterable):
if isinstance(arr1,collections.abc.Iterable):
for elemindex,elem in enumerate(arr1):
if type(elem) == str:
if softStringCompare == True: #if using softStringCompare
Expand All @@ -78,7 +78,7 @@ def subtractNested(arr1,arr2,subtractionResult, relativeTolerance=None, absolute
else:
subtractionResult[elemindex] = 1
else:
if isinstance(elem,collections.Iterable):
if isinstance(elem,collections.abc.Iterable):
subtractNested(arr1[elemindex],arr2[elemindex],subtractionResult[elemindex], relativeTolerance=relativeTolerance, absoluteTolerance=absoluteTolerance, softStringCompare=softStringCompare)
else: #this is for final elements, like integers and floats.
#we do allow approximate comparisons using the variables relativeTolerance and absoluteTolerance
Expand Down Expand Up @@ -114,13 +114,13 @@ def subtractNested(arr1,arr2,subtractionResult, relativeTolerance=None, absolute
def nested_iter_to_nested_list(iterReceived):
#The first two lines are justs to return the object immediately if it's not an iterable.
#This is mostly to prevent bugs if someone tries to feed an integer, for example.
if not isinstance(iterReceived,collections.Iterable):
if not isinstance(iterReceived,collections.abc.Iterable):
return iterReceived
list_at_this_level = list(iterReceived)
for elemIndex, elem in enumerate(iterReceived):
#A string is iterable and a single value in a string is also iterable
#So check to see if it is not a string to avoid recursion error
if isinstance(elem,collections.Iterable) and type(elem) != str:
if isinstance(elem,collections.abc.Iterable) and type(elem) != str:
list_at_this_level[elemIndex] = nested_iter_to_nested_list(elem)
else:
list_at_this_level[elemIndex] = elem
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
EMAIL = '[email protected]'
AUTHOR = 'Aditya Savara'
REQUIRES_PYTHON = '>=3.0.0'
VERSION = '5.1.2'
VERSION = '5.1.3'
LICENSE = 'BSD-3-Clause'

# What packages are required for this module to be executed?
Expand Down

0 comments on commit fe2a089

Please sign in to comment.