-
-
Notifications
You must be signed in to change notification settings - Fork 430
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
Mirroring C enums in Python for CMontecarlo tests. #540
Conversation
- Corresponding changes in test_cmontecarlo.py and struct.py also included here.
That looks like an interesting addition and makes the code more readable - well done @karandesai-96 |
from ctypes import c_int | ||
|
||
|
||
class EnumerationType(type(c_int)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Normally, when we copy code from the internet we like to attribute it with the original source. In science this is an important part to understand the source of information. Can you add one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Added.
Thanks @wkerzendorf. I will work upon the suggestions received here and wrap up here with a couple of docstrings 😉 |
I'm signing off on this piece of code. It looks good (as far as I understand). @yeganer - you can merge it tomorrow if you are happy as well. |
Looks good to me, I'll merge. |
This modification is causing occasional segfaults, so it needs to be modified. |
There are certain parameters, such as
RPacket.status
andStorageModel.cont_status
which are C enum datatypes. Enums were considered asctypes.c_uint
orctypes.c_int
in Python, and implemented in that manner.This PR adds a new file, enum.py which sets up a mirror for C enums in python. Enums are not supported directly in
ctypes
so a Meta Class and corresponding Class were written.Following were mirrored for Python tests and used:
This targets improvement in readability of tests.