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

Add as checks with tests #192

Merged
merged 15 commits into from
Oct 26, 2020

Conversation

swamper123
Copy link
Contributor

Adds two checks for as request purposes as sync/wrapper method, Tests included.

I want to mention, that check_as_completion is triggering errors, because a PendingError is logged as "Other Socker error(1)" in logger.error level. So these will appear always, if a job is pending (which is annoying).

Either there is a way we may "ignore" this error in case it is just a pending job or we have to live with those unecessarry logs.
The logger.level for the "ignore that" message is error, so it appears with the PendingError log as well (otherwise this may be confusing when errors are logged but the "don't worry" log doesn't show up).

Fabian Beitler added 7 commits September 15, 2020 08:58
Add check_as_completion
Add tests for both
Add BaseExceptions for other possible thrown errors
Add exception block to catch PendingErrors, which are logged as errors
Replace bare exception block with better ones
Add missing as_ prefix to as_db_get test.
@swamper123
Copy link
Contributor Author

swamper123 commented Sep 15, 2020

Because all as_methods are affected to be faulty without propper checks, I have made a fix for as_db_read without a test of itself.
It is a rat-bites-own-tail problem: Create as_check and then other as_methods, but you can't test as_checks without as_methods, but you can't check as_methods without as_checks ....
But like mentioned in issue #164 and perhaps #26 as well, a pointer should be returned, then propper checked via mentioned methods and then use bytearray() to convert the correct data into a bytearray. This would be a more clean way to handle as_methods.

snap7/client.py Outdated Show resolved Hide resolved
snap7/client.py Outdated Show resolved Hide resolved
snap7/client.py Outdated Show resolved Hide resolved
test/test_client.py Outdated Show resolved Hide resolved
test/test_client.py Outdated Show resolved Hide resolved
test/test_client.py Outdated Show resolved Hide resolved
Fabian Beitler added 2 commits September 22, 2020 08:52
@swamper123
Copy link
Contributor Author

Any other thoughts?

remove obsolete try_except block to catch other socket error
remove obsolete logging in test
@swamper123
Copy link
Contributor Author

Hmm is travis not running, because review is still pending? 😕

test/test_client.py Outdated Show resolved Hide resolved
test/test_client.py Outdated Show resolved Hide resolved
…thrown

Add tries for test_wait_as_completion_timeout, because timeout can't be evoked sometimes.
Add skipTest to test_wait_as_completion_timeout, in case no timeout evoked after x tries.
@swamper123 swamper123 requested a review from gijzelaerr October 6, 2020 09:02
test/test_client.py Outdated Show resolved Hide resolved
@swamper123
Copy link
Contributor Author

swamper123 commented Oct 15, 2020

Does anyone have a clue why Travis is not triggered anymore?

EDIT: ...Strange ... well I got a report sended to me, but it is not appearing here.

EDIT2: Now even Travis is happy. ^^

@gijzelaerr
Copy link
Owner

the builds are triggered but somehow travis does not report back to github anymore https://travis-ci.org/github/gijzelaerr/python-snap7/builds/735967984

return
except BaseException as pyt_err:
self.fail(f"Exception was thrown: {pyt_err}")
self.skipTest(f"After {tries} tries, no timout could be envoked. Skip test.")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't want to skip on timeout, just fail

for i in range(tries):
self.client.as_db_read(dbnumber, start, size)
try:
self.client.wait_as_completion(ctypes.c_ulong(0))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the try except can be removed here, the test will then just fail if an exception is raised, no reason to capture it and manually fail

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method itself is raising an Snap7Exception in case of a timeout, which is the original behaviour of the snap7 version as well.
The goal of this test is to catch this Snap7Exception"CLI : Job Timeout" so that the behaviour of wait_as_completion(...) in case of a Job Timeout can be tested. It is possible that other Snap7Exceptions may be raised, so these have to be caught and checked.
I agree with the BaseException below in this case.

self.client.wait_as_completion(ctypes.c_ulong(timeout))
except Snap7Exception as s7_err:
if s7_err.args[0] == b'CLI : Job Timeout':
self.fail(f"Request was timeouted after {timeout} seconds - FAIL")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the try except can be removed here, the test will then just fail if an exception is raised, no reason to capture it and manually fail

test/test_client.py Outdated Show resolved Hide resolved
test/test_client.py Outdated Show resolved Hide resolved
snap7/client.py Outdated Show resolved Hide resolved
@swamper123 swamper123 requested a review from gijzelaerr October 26, 2020 09:28
Copy link
Owner

@gijzelaerr gijzelaerr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one last thing

except Snap7Exception as s7_err:
if not s7_err.args[0] == b'CLI : Job Timeout':
self.fail(f"While waiting another error appeared: {s7_err}")
return
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you return here? shouldn't it just continue?

Copy link
Contributor Author

@swamper123 swamper123 Oct 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise I would stuck in the loop, testing the behaviour multiple times(which is unnecessarry) and then, if the loop would be done, the test would fail.

So if once a Job Timeout was raised correctly, the test shall stop here and pass (via return).

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yes, skimmed too quickly.

@swamper123 swamper123 requested a review from gijzelaerr October 26, 2020 10:25
except Snap7Exception as s7_err:
if not s7_err.args[0] == b'CLI : Job Timeout':
self.fail(f"While waiting another error appeared: {s7_err}")
return
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yes, skimmed too quickly.

@gijzelaerr gijzelaerr merged commit 61c970c into gijzelaerr:master Oct 26, 2020
@gijzelaerr gijzelaerr added this to the 0.12 milestone Oct 26, 2020
@swamper123 swamper123 deleted the add_as_checks_with_tests branch October 26, 2020 12:55
@gijzelaerr gijzelaerr modified the milestones: 0.12, 1.0 Jan 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants