Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore nonzero nanoseconds warning #360

Merged
merged 16 commits into from
Aug 17, 2023
4 changes: 2 additions & 2 deletions docs/APILibraryDocumentation.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/GUILibraryDocumentation.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/SOAPLibraryDocumentation.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions samples/GUITests.robot
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ Wait Until Element Contains Value
Get Element CSS Attribute Value
Go to https://www.w3schools.com/html/html_examples.asp
${value}= Get Element CSS Attribute Value //div[@id='googleSearch'] position
Should Be Equal ${value} absolute
Should Be Equal ${value} fixed

Element CSS Attribute Value Should Be
Go to https://www.w3schools.com/html/html_examples.asp
Element CSS Attribute Value Should Be //div[@id='googleSearch'] position absolute
Element CSS Attribute Value Should Be //div[@id='googleSearch'] position fixed
8 changes: 5 additions & 3 deletions src/Zoomba/APILibrary.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import datetime
import json
import warnings

from RequestsLibrary import RequestsLibrary, utils
from dateutil.parser import parse
Expand Down Expand Up @@ -225,63 +226,63 @@
else:
zoomba.fail("The response is not a list:\nActual Response:\n" + str(actual_response_dict))

def key_by_key_validator(self, actual_dictionary, expected_dictionary, ignored_keys=None, unmatched_keys_list=None,
parent_key=None, full_list_validation=False, sort_lists=False, **kwargs):
""" This method is used to find and verify the value of every key in the expectedItem dictionary when compared
against a single dictionary actual_item, unless any keys are included on the ignored_keys array./n

actual_item: (array of dictionaries) The list of dictionary items extracted from a json Response.\n
ExpectedItem: (dictionary) The expected item with the key to be validated.\n
ignored_keys: (strings list) A list of strings of the keys to be ignored on the validation.\n
full_list_validation: (bool) Check that the entire list matches the expected response, defaults to False.\n
sort_lists: (bool) Sort lists before doing key by key validation, defaults to False.\n
**kwargs: (dict) Currently supported kwargs are margin_type and margin_amt\n
margin_type: (string) The type of unit of time to be used to generate a delta for the date comparisons.\n
margin_amt: (string/#) The amount of units specified in margin_type to allot for difference between dates.\n
return: (boolean) If the method completes successfully, it returns True. Appropriate error messages are
returned otherwise.\n
"""
if len(actual_dictionary) != len(expected_dictionary):
zoomba.fail("Collections not the same length:"
"\nActual length: " + str(len(actual_dictionary)) +
"\nExpected length " + str(len(expected_dictionary)))
return
for key, value in expected_dictionary.items():
if ignored_keys and key in ignored_keys:
continue
if key not in actual_dictionary:
zoomba.fail("Key not found in Actual : " + str(actual_dictionary) + " Key: " + str(key))
continue
if isinstance(value, list):
if full_list_validation and len(value) != len(actual_dictionary[key]):
zoomba.fail("Arrays not the same length:" +
"\nExpected: " + str(value) +
"\nActual: " + str(actual_dictionary[key]))
continue
self._key_by_key_list(key, value, actual_dictionary, unmatched_keys_list, ignored_keys, parent_key,
full_list_validation=full_list_validation, sort_lists=sort_lists, **kwargs)
elif isinstance(value, dict):
self._key_by_key_dict(key, value, actual_dictionary, expected_dictionary, unmatched_keys_list,
ignored_keys, full_list_validation=full_list_validation, sort_lists=sort_lists,
**kwargs)
elif (isinstance(expected_dictionary[key], str) and not expected_dictionary[key].isdigit()) or isinstance(expected_dictionary[key], datetime.datetime):
try:
if not isinstance(expected_dictionary[key], datetime.datetime):
parse(expected_dictionary[key])
self.date_string_comparator(value, actual_dictionary[key], key, unmatched_keys_list, **kwargs)
except (ValueError, TypeError):
if value == actual_dictionary[key]:
continue
else:
unmatched_keys_list.append(("------------------\n" + "Key: " + str(key),
"Expected: " + str(value),
"Actual: " + str(actual_dictionary[key])))
elif value == actual_dictionary[key]:
continue
else:
unmatched_keys_list.append(("------------------\n" + "Key: " + str(key), "Expected: " + str(value),
"Actual: " + str(actual_dictionary[key])))
return True

Check notice on line 285 in src/Zoomba/APILibrary.py

View check run for this annotation

codefactor.io / CodeFactor

src/Zoomba/APILibrary.py#L229-L285

Complex Method

def date_string_comparator(self, expected_date, actual_date, key, unmatched_keys_list, **kwargs):
"""This Method is used to validate a single property on a JSON object of the Date Type.
Expand Down Expand Up @@ -354,9 +355,9 @@
"\nActual: " + str(sorted(actual_dictionary[key])))
continue
else:
zoomba.fail("Arrays do not match:" + \
"\nExpected: " + str(value) + \
"\nActual: " + str(actual_dictionary[key]) + \
zoomba.fail("Arrays do not match:" +
"\nExpected: " + str(value) +
"\nActual: " + str(actual_dictionary[key]) +
"\nIf this is simply out of order try 'sort_list=True'")
continue
else:
Expand Down Expand Up @@ -454,6 +455,7 @@

def _date_format(date_string, key, unmatched_keys_list, date_type, date_format=None):
formatted_date = None
warnings.filterwarnings("ignore", message=".*Discarding nonzero nanoseconds in conversion.*")
if (date_format is None) and (date_string is not None):
try:
formatted_date = to_datetime(date_string).tz_localize(None).to_pydatetime()
Expand Down
7 changes: 7 additions & 0 deletions test/API/test_dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../../src/')))
import datetime
import unittest
import warnings
from Zoomba.APILibrary import APILibrary
from Zoomba.APILibrary import _date_format

Expand Down Expand Up @@ -78,3 +79,9 @@ def test__date_format_unique_date_formats_fail(self):
_date_format("210568/05/05 05:05:05", "key", unmatched, "string", "%Y/%m/%d %H:%M:%S")
assert unmatched == [('------------------\nKey: key', 'string Date Not Correct Format:',
'Expected Format: %Y/%m/%d %H:%M:%S', 'Date: 210568/05/05 05:05:05')]

def test_nonzero_nanoseconds_cutoff_no_warning(self):
with warnings.catch_warnings():
warnings.simplefilter("error")
date = datetime.datetime(2018, 5, 5, 5, 5, 5, 123456)
assert date == _date_format("2018-05-05T05:05:05.123456789", "key", [], "string")
4 changes: 2 additions & 2 deletions test/GUI/GUITests.robot
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,12 @@ Get Element CSS Attribute Value
[Teardown] Close All Browsers
Test Case Setup https://www.w3schools.com/html/html_examples.asp
${value}= Get Element CSS Attribute Value //div[@id='googleSearch'] position
Should Be Equal ${value} absolute
Should Be Equal ${value} fixed

Element CSS Attribute Value Should Be
[Teardown] Close All Browsers
Test Case Setup https://www.w3schools.com/html/html_examples.asp
Element CSS Attribute Value Should Be //div[@id='googleSearch'] position absolute
Element CSS Attribute Value Should Be //div[@id='googleSearch'] position fixed

Get React List Items Test
[Setup] Test Case Setup https://react-select.com/home
Expand Down
4 changes: 2 additions & 2 deletions test/GUI/GUITestsEdge.robot
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,11 @@ Wait Until Element Contains Value
Get Element CSS Attribute Value
Go To https://www.w3schools.com/html/html_examples.asp
${value}= Get Element CSS Attribute Value //div[@id='googleSearch'] position
Should Be Equal ${value} absolute
Should Be Equal ${value} fixed

Element CSS Attribute Value Should Be
Go To https://www.w3schools.com/html/html_examples.asp
Element CSS Attribute Value Should Be //div[@id='googleSearch'] position absolute
Element CSS Attribute Value Should Be //div[@id='googleSearch'] position fixed

Get React List Items Test
Go To https://react-select.com/home
Expand Down
Loading