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

Testing for the command line interface. #223

Merged
merged 49 commits into from
Jan 7, 2025
Merged

Conversation

lnevay
Copy link
Contributor

@lnevay lnevay commented Jan 4, 2025

Extended the parser class to optionally throw an exception instead of the exit so not all are exits and we can see the right exception.

Added tests for all options. Many tests pass on the basis that they should raise a NotImplementedError exception.

Fixed a decent number of minor bugs. The big one was that a lot of the arguments were in the wrong order for the cli function. Finished off some implementations also.

@lnevay lnevay requested a review from stewartboogert January 4, 2025 13:21
@lnevay
Copy link
Contributor Author

lnevay commented Jan 4, 2025

@stewartboogert some cli tests will fail just now (5), but these are due to 3 bugs I'm not sure about actually in the main code and not the cli. If you could have a look that'd really help. Cheers!

@lnevay
Copy link
Contributor Author

lnevay commented Jan 5, 2025

Fixed the tests and little bugs. Now, the only tests failing are from genat42Fluka. There is some byte reading error but I'm reasonably sure this is unrelated to this pull request.

FAILED tests/convert/test_geant42Fluka.py::test_Geant42FlukaConversion_T326_ManyGenericTrap - UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 56: ordinal not in range(128)

@lnevay
Copy link
Contributor Author

lnevay commented Jan 6, 2025

So the tests that fail are on writing fluka (not touched in this pull request). The fluka registry tries to read the low energy neutron cards template file and fails there. So the error is the ascii encoding of the package files.

/opt/hostedtoolcache/Python/3.9.20/x64/lib/python3.9/site-packages/pyg4ometry/fluka/fluka_registry.py:239: in addLowMatAllMaterials
    mgXS = multiGroupNeutronCrossSections()
        self       = <pyg4ometry.fluka.fluka_registry.FlukaRegistry object at 0x7f705601ccd0>
/opt/hostedtoolcache/Python/3.9.20/x64/lib/python3.9/site-packages/pyg4ometry/fluka/material.py:107: in __init__
    self._readFile()
        fileName   = None
        files      = <function files at 0x7f70aba71f70>
        self       = <pyg4ometry.fluka.material.multiGroupNeutronCrossSections object at 0x7f7055c6da00>
/opt/hostedtoolcache/Python/3.9.20/x64/lib/python3.9/site-packages/pyg4ometry/fluka/material.py:111: in _readFile
    for l in f:
        f          = <_io.TextIOWrapper name='/opt/hostedtoolcache/Python/3.9.20/x64/lib/python3.9/site-packages/pyg4ometry/fluka/fluka_lowenergyneut.txt' mode='r' encoding='ANSI_X3.4-1968'>
        self       = <pyg4ometry.fluka.material.multiGroupNeutronCrossSections object at 0x7f7055c6da00>
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <encodings.ascii.IncrementalDecoder object at 0x7f7055c6d400>
input = b'H, H2O bound natural Hydrogen,     296 K, ENDF/B-VIIR0, \xe2\x9c\x93, HYDROGEN, 1, -2,    296, \xe2\x9c\x93\nH, CH2 ...c\x93\n208Pb, Lead 208, self-shielded,      296 K, ENDF/B-VIR8,  \xe2\x9c\x93,208-PB,    82, 1208, 296, \xe2\x9c\x93\n'
final = False

    def decode(self, input, final=False):
>       return codecs.ascii_decode(input, self.errors)[0]
E       UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 56: ordinal not in range(128)

final      = False
input      = b'H, H2O bound natural Hydrogen,     296 K, ENDF/B-VIIR0, \xe2\x9c\x93, HYDROGEN, 1, -2,    296, \xe2\x9c\x93\nH, CH2 ...c\x93\n208Pb, Lead 208, self-shielded,      296 K, ENDF/B-VIR8,  \xe2\x9c\x93,208-PB,    82, 1208, 296, \xe2\x9c\x93\n'
self       = <encodings.ascii.IncrementalDecoder object at 0x7f7055c6d400>

Copy link

codecov bot commented Jan 6, 2025

Codecov Report

Attention: Patch coverage is 71.56863% with 29 lines in your changes missing coverage. Please review.

Project coverage is 75.57%. Comparing base (f0fddf1) to head (48f2e1e).
Report is 56 commits behind head on main.

Files with missing lines Patch % Lines
src/pyg4ometry/cli.py 72.63% 26 Missing ⚠️
src/pyg4ometry/visualisation/ViewerBase.py 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #223      +/-   ##
==========================================
+ Coverage   74.09%   75.57%   +1.47%     
==========================================
  Files         157      157              
  Lines       22752    22822      +70     
==========================================
+ Hits        16859    17248     +389     
+ Misses       5893     5574     -319     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

lnevay and others added 6 commits January 6, 2025 11:51
…asily do this as exceptions could really be throw at many places in main. This ensures clean print out for users, but still good debugging and testing and avoids sprinkling exits deeper in the code. Technically, the if __main__ isn't needed at the end as it's an entrypoint.
@lnevay
Copy link
Contributor Author

lnevay commented Jan 6, 2025

Fluka conversion tests now pass. This was fixed by forcing the writer to read the the low material template file using 'utf-8' encoding explicitly (see d65e2a8). I'm can't see how this was related to the changes here, but it does fix it. All tests passing now.

Copy link
Member

@gipert gipert left a comment

Choose a reason for hiding this comment

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

Nice! I would only recommend to squash the pre-commit bot commits into the previous one with git rebase -i (and then force-push), if you can.

@stewartboogert stewartboogert merged commit 5da9ced into g4edge:main Jan 7, 2025
17 checks passed
@lnevay lnevay deleted the cli-test branch January 7, 2025 21:53
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.

3 participants