mirror of
https://github.com/pim-n/pg-rad
synced 2026-03-22 21:48:11 +01:00
update exceptions and main.py (including test case)
This commit is contained in:
@ -10,6 +10,10 @@ class InvalidCSVError(DataLoadError):
|
|||||||
"""Raised when a file is not a valid CSV."""
|
"""Raised when a file is not a valid CSV."""
|
||||||
|
|
||||||
|
|
||||||
|
class InvalidYAMLError(DataLoadError):
|
||||||
|
"""Raised when a file is not a valid YAML."""
|
||||||
|
|
||||||
|
|
||||||
class OutOfBoundsError(Exception):
|
class OutOfBoundsError(Exception):
|
||||||
"""Raised when an object is attempted to be placed out of bounds."""
|
"""Raised when an object is attempted to be placed out of bounds."""
|
||||||
|
|
||||||
@ -18,7 +22,11 @@ class MissingConfigKeyError(KeyError):
|
|||||||
"""Raised when a (nested) config key is missing in the config."""
|
"""Raised when a (nested) config key is missing in the config."""
|
||||||
def __init__(self, key, subkey=None):
|
def __init__(self, key, subkey=None):
|
||||||
if subkey:
|
if subkey:
|
||||||
self.message = f"Missing key in {key}: {', '.join(list(subkey))}"
|
if isinstance(subkey, str):
|
||||||
|
pass
|
||||||
|
elif isinstance(subkey, set):
|
||||||
|
subkey = ', '.join(list(subkey))
|
||||||
|
self.message = f"Missing key in {key}: {subkey}"
|
||||||
else:
|
else:
|
||||||
self.message = f"Missing key: {key}"
|
self.message = f"Missing key: {key}"
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,6 @@ import logging
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
from pandas.errors import ParserError
|
from pandas.errors import ParserError
|
||||||
from yaml import YAMLError
|
|
||||||
|
|
||||||
from pg_rad.detector.builder import DetectorBuilder
|
from pg_rad.detector.builder import DetectorBuilder
|
||||||
from pg_rad.exceptions.exceptions import (
|
from pg_rad.exceptions.exceptions import (
|
||||||
@ -11,7 +10,8 @@ from pg_rad.exceptions.exceptions import (
|
|||||||
OutOfBoundsError,
|
OutOfBoundsError,
|
||||||
DimensionError,
|
DimensionError,
|
||||||
InvalidConfigValueError,
|
InvalidConfigValueError,
|
||||||
InvalidIsotopeError
|
InvalidIsotopeError,
|
||||||
|
InvalidYAMLError
|
||||||
)
|
)
|
||||||
from pg_rad.logger.logger import setup_logger
|
from pg_rad.logger.logger import setup_logger
|
||||||
from pg_rad.inputparser.parser import ConfigParser
|
from pg_rad.inputparser.parser import ConfigParser
|
||||||
@ -59,12 +59,14 @@ def main():
|
|||||||
length: 1000
|
length: 1000
|
||||||
segments:
|
segments:
|
||||||
- straight
|
- straight
|
||||||
|
- turn_left
|
||||||
|
direction: negative
|
||||||
|
|
||||||
sources:
|
sources:
|
||||||
test_source:
|
test_source:
|
||||||
activity_MBq: 1000
|
activity_MBq: 100
|
||||||
position: [500, 100, 0]
|
position: [250, 100, 0]
|
||||||
isotope: CS137
|
isotope: Cs137
|
||||||
|
|
||||||
detector:
|
detector:
|
||||||
name: dummy
|
name: dummy
|
||||||
@ -100,8 +102,7 @@ def main():
|
|||||||
plotter.plot()
|
plotter.plot()
|
||||||
except (
|
except (
|
||||||
MissingConfigKeyError,
|
MissingConfigKeyError,
|
||||||
KeyError,
|
KeyError
|
||||||
YAMLError,
|
|
||||||
) as e:
|
) as e:
|
||||||
logger.critical(e)
|
logger.critical(e)
|
||||||
logger.critical(
|
logger.critical(
|
||||||
@ -125,8 +126,10 @@ def main():
|
|||||||
|
|
||||||
except (
|
except (
|
||||||
FileNotFoundError,
|
FileNotFoundError,
|
||||||
ParserError
|
ParserError,
|
||||||
):
|
InvalidYAMLError
|
||||||
|
) as e:
|
||||||
|
logger.critical(e)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user