geolysis 0.7.3__tar.gz → 0.8.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. {geolysis-0.7.3 → geolysis-0.8.0}/PKG-INFO +1 -2
  2. {geolysis-0.7.3 → geolysis-0.8.0}/README.md +0 -1
  3. {geolysis-0.7.3 → geolysis-0.8.0}/geolysis/__init__.py +1 -1
  4. {geolysis-0.7.3 → geolysis-0.8.0}/geolysis/bearing_capacity/abc/cohl/__init__.py +12 -11
  5. {geolysis-0.7.3 → geolysis-0.8.0}/geolysis/bearing_capacity/abc/cohl/_core.py +2 -1
  6. {geolysis-0.7.3 → geolysis-0.8.0}/geolysis/bearing_capacity/ubc/__init__.py +7 -6
  7. {geolysis-0.7.3 → geolysis-0.8.0}/geolysis/bearing_capacity/ubc/terzaghi_ubc.py +1 -1
  8. {geolysis-0.7.3 → geolysis-0.8.0}/geolysis/foundation.py +14 -9
  9. {geolysis-0.7.3 → geolysis-0.8.0}/geolysis/soil_classifier.py +11 -8
  10. {geolysis-0.7.3 → geolysis-0.8.0}/geolysis/spt.py +37 -14
  11. geolysis-0.8.0/geolysis/utils/exceptions.py +52 -0
  12. geolysis-0.8.0/geolysis/utils/validators.py +129 -0
  13. {geolysis-0.7.3 → geolysis-0.8.0}/geolysis.egg-info/PKG-INFO +1 -2
  14. {geolysis-0.7.3 → geolysis-0.8.0}/tests/test_soil_classifier.py +3 -0
  15. {geolysis-0.7.3 → geolysis-0.8.0}/tests/test_spt.py +28 -13
  16. geolysis-0.7.3/geolysis/utils/exceptions.py +0 -36
  17. geolysis-0.7.3/geolysis/utils/validators.py +0 -101
  18. {geolysis-0.7.3 → geolysis-0.8.0}/LICENSE.txt +0 -0
  19. {geolysis-0.7.3 → geolysis-0.8.0}/geolysis/bearing_capacity/__init__.py +0 -0
  20. {geolysis-0.7.3 → geolysis-0.8.0}/geolysis/bearing_capacity/abc/__init__.py +0 -0
  21. {geolysis-0.7.3 → geolysis-0.8.0}/geolysis/bearing_capacity/abc/cohl/bowles_abc.py +0 -0
  22. {geolysis-0.7.3 → geolysis-0.8.0}/geolysis/bearing_capacity/abc/cohl/meyerhof_abc.py +0 -0
  23. {geolysis-0.7.3 → geolysis-0.8.0}/geolysis/bearing_capacity/abc/cohl/terzaghi_abc.py +0 -0
  24. {geolysis-0.7.3 → geolysis-0.8.0}/geolysis/bearing_capacity/ubc/_core.py +0 -0
  25. {geolysis-0.7.3 → geolysis-0.8.0}/geolysis/bearing_capacity/ubc/hansen_ubc.py +0 -0
  26. {geolysis-0.7.3 → geolysis-0.8.0}/geolysis/bearing_capacity/ubc/vesic_ubc.py +0 -0
  27. {geolysis-0.7.3 → geolysis-0.8.0}/geolysis/utils/__init__.py +0 -0
  28. {geolysis-0.7.3 → geolysis-0.8.0}/geolysis.egg-info/SOURCES.txt +0 -0
  29. {geolysis-0.7.3 → geolysis-0.8.0}/geolysis.egg-info/dependency_links.txt +0 -0
  30. {geolysis-0.7.3 → geolysis-0.8.0}/geolysis.egg-info/requires.txt +0 -0
  31. {geolysis-0.7.3 → geolysis-0.8.0}/geolysis.egg-info/top_level.txt +0 -0
  32. {geolysis-0.7.3 → geolysis-0.8.0}/pyproject.toml +0 -0
  33. {geolysis-0.7.3 → geolysis-0.8.0}/setup.cfg +0 -0
  34. {geolysis-0.7.3 → geolysis-0.8.0}/setup.py +0 -0
  35. {geolysis-0.7.3 → geolysis-0.8.0}/tests/test_foundation.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: geolysis
3
- Version: 0.7.3
3
+ Version: 0.8.0
4
4
  Summary: geolysis is an opensource software for geotechnical engineering analysis and modeling.
5
5
  Author-email: Patrick Boateng <boatengpato.pb@gmail.com>
6
6
  License: MIT License
@@ -134,7 +134,6 @@ Here are brief descriptions of the `geolysis` projects:
134
134
 
135
135
  - [Installation](#installation)
136
136
  - [Usage Example](#usage-example)
137
- - [Features](#features)
138
137
  - [Documentation](#documentation)
139
138
  - [Contributing](#contributing)
140
139
  - [License](#license)
@@ -102,7 +102,6 @@ Here are brief descriptions of the `geolysis` projects:
102
102
 
103
103
  - [Installation](#installation)
104
104
  - [Usage Example](#usage-example)
105
- - [Features](#features)
106
105
  - [Documentation](#documentation)
107
106
  - [Contributing](#contributing)
108
107
  - [License](#license)
@@ -1,5 +1,5 @@
1
1
  from . import foundation, soil_classifier, spt
2
2
 
3
- __version__ = "0.7.3"
3
+ __version__ = "0.8.0"
4
4
 
5
5
  __all__ = ["foundation", "soil_classifier", "spt"]
@@ -3,12 +3,11 @@ allowable bearing capacity calculations using methods like Bowles, Meyerhof,
3
3
  and Terzaghi for various foundation types and shapes.
4
4
  """
5
5
  import enum
6
- from codecs import backslashreplace_errors
7
6
  from typing import Optional
8
7
 
9
8
  from geolysis.foundation import FoundationType, Shape, create_foundation
10
9
  from geolysis.utils import enum_repr, inf
11
- from geolysis.utils.exceptions import EnumErrorMsg
10
+ from geolysis.utils.exceptions import ErrorMsg, ValidationError
12
11
 
13
12
  from ._core import AllowableBearingCapacity
14
13
  from .bowles_abc import BowlesABC4MatFoundation, BowlesABC4PadFoundation
@@ -99,25 +98,27 @@ def create_allowable_bearing_capacity(corrected_spt_n_value: float,
99
98
  :raises ValueError: Raised if an invalid footing ``shape`` is provided.
100
99
  """
101
100
 
102
- msg = EnumErrorMsg(param_name="abc_type",
103
- param_value=abc_type,
104
- param_type=ABCType)
101
+ msg = ErrorMsg(param_name="abc_type",
102
+ param_value=abc_type,
103
+ symbol="in",
104
+ param_value_bound=list(ABCType))
105
105
 
106
106
  if abc_type is None:
107
- raise ValueError(msg)
107
+ raise ValidationError(msg)
108
108
 
109
109
  try:
110
110
  abc_type = ABCType(str(abc_type).casefold())
111
111
  except ValueError as e:
112
- raise ValueError(msg) from e
112
+ raise ValidationError(msg) from e
113
113
 
114
114
  try:
115
115
  foundation_type = FoundationType(str(foundation_type).casefold())
116
116
  except ValueError as e:
117
- msg = EnumErrorMsg(param_name="foundation_type",
118
- param_value=foundation_type,
119
- param_type=FoundationType)
120
- raise ValueError(msg) from e
117
+ msg = ErrorMsg(param_name="foundation_type",
118
+ param_value=foundation_type,
119
+ symbol="in",
120
+ param_value_bound=list(FoundationType))
121
+ raise ValidationError(msg) from e
121
122
 
122
123
  # exception from create_foundation will automaatically propagate
123
124
  # no need to catch and handle it.
@@ -1,7 +1,8 @@
1
1
  from abc import ABC, abstractmethod
2
2
 
3
3
  from geolysis.foundation import FoundationSize
4
- from geolysis.utils import validators, exceptions as exc
4
+ from geolysis.utils import exceptions as exc
5
+ from geolysis.utils import validators
5
6
 
6
7
 
7
8
  class AllowableBearingCapacity(ABC):
@@ -8,7 +8,7 @@ from typing import Optional
8
8
 
9
9
  from geolysis.foundation import Shape, create_foundation
10
10
  from geolysis.utils import enum_repr
11
- from geolysis.utils.exceptions import EnumErrorMsg
11
+ from geolysis.utils.exceptions import ErrorMsg, ValidationError
12
12
 
13
13
  from ._core import UltimateBearingCapacity
14
14
  from .hansen_ubc import HansenUltimateBearingCapacity
@@ -116,17 +116,18 @@ def create_ultimate_bearing_capacity(friction_angle: float,
116
116
  :raises ValueError: Raised if an invalid footing shape is provided.
117
117
  """
118
118
 
119
- msg = EnumErrorMsg(param_name="ubc_type",
120
- param_value=ubc_type,
121
- param_type=UBCType)
119
+ msg = ErrorMsg(param_name="ubc_type",
120
+ param_value=ubc_type,
121
+ symbol="in",
122
+ param_value_bound=list(UBCType))
122
123
 
123
124
  if ubc_type is None:
124
- raise ValueError(msg)
125
+ raise ValidationError(msg)
125
126
 
126
127
  try:
127
128
  ubc_type = UBCType(str(ubc_type).casefold())
128
129
  except ValueError as e:
129
- raise ValueError(msg) from e
130
+ raise ValidationError(msg) from e
130
131
 
131
132
  # exception from create_foundation will automatically propagate
132
133
  # no need to catch and handle it.
@@ -60,7 +60,7 @@ class TerzaghiUltimateBearingCapacity(UltimateBearingCapacity, ABC):
60
60
 
61
61
  :Equation:
62
62
 
63
- .. math:: N_{\gamma} &= (N_q - 1) \cdot \tan(1.4\phi)
63
+ .. math:: N_{\gamma} = (N_q - 1) \cdot \tan(1.4\phi)
64
64
  """
65
65
  return n_gamma(self.friction_angle)
66
66
 
@@ -5,7 +5,7 @@ from abc import ABC, abstractmethod
5
5
  from typing import Optional, TypeVar
6
6
 
7
7
  from .utils import enum_repr, inf, isclose, validators
8
- from .utils.exceptions import EnumErrorMsg, ErrorMsg
8
+ from .utils.exceptions import ErrorMsg, ValidationError
9
9
 
10
10
  __all__ = ["create_foundation",
11
11
  "FoundationSize",
@@ -31,8 +31,10 @@ class Shape(enum.StrEnum):
31
31
  @enum_repr
32
32
  class FoundationType(enum.StrEnum):
33
33
  """Enumeration of foundation types."""
34
- PAD = ISOLATED = enum.auto()
35
- MAT = RAFT = enum.auto()
34
+ PAD = enum.auto()
35
+ ISOLATED = PAD
36
+ MAT = enum.auto()
37
+ RAFT = MAT
36
38
 
37
39
 
38
40
  class FootingSize(ABC):
@@ -376,10 +378,11 @@ def create_foundation(depth: float,
376
378
  try:
377
379
  shape = Shape(str(shape).casefold())
378
380
  except ValueError as e:
379
- msg = EnumErrorMsg(param_name="shape",
380
- param_value=shape,
381
- param_type=Shape)
382
- raise ValueError(msg) from e
381
+ msg = ErrorMsg(param_name="shape",
382
+ param_value=shape,
383
+ symbol="in",
384
+ param_value_bound=list(Shape))
385
+ raise ValidationError(msg) from e
383
386
 
384
387
  if shape is Shape.STRIP:
385
388
  footing_size = StripFooting(width=width)
@@ -389,8 +392,10 @@ def create_foundation(depth: float,
389
392
  footing_size = CircularFooting(diameter=width)
390
393
  else: # RECTANGLE
391
394
  if not length:
392
- msg = ErrorMsg(msg="Length of footing must be provided.")
393
- raise ValueError(msg)
395
+ msg = ErrorMsg(param_name="length",
396
+ param_value=length,
397
+ msg="Length of footing must be provided.")
398
+ raise ValidationError(msg)
394
399
  footing_size = RectangularFooting(width=width, length=length)
395
400
 
396
401
  return FoundationSize(depth=depth,
@@ -5,7 +5,7 @@ import enum
5
5
  from typing import NamedTuple, Optional, Sequence
6
6
 
7
7
  from .utils import enum_repr, isclose, round_, validators
8
- from .utils.exceptions import EnumErrorMsg, ErrorMsg
8
+ from .utils.exceptions import ErrorMsg, ValidationError
9
9
 
10
10
  __all__ = ["ClfType",
11
11
  "AtterbergLimits",
@@ -713,17 +713,18 @@ def create_soil_classifier(liquid_limit: float,
713
713
  :raises ValueError: Raises ValueError if ``sand`` is not provided for
714
714
  :class:`USCS` classification.
715
715
  """
716
- msg = EnumErrorMsg(param_name="clf_type",
717
- param_value=clf_type,
718
- param_type=ClfType)
716
+ msg = ErrorMsg(param_name="clf_type",
717
+ param_value=clf_type,
718
+ symbol="in",
719
+ param_value_bound=list(ClfType))
719
720
 
720
721
  if clf_type is None:
721
- raise ValueError(msg)
722
+ raise ValidationError(msg)
722
723
 
723
724
  try:
724
725
  clf_type = ClfType(str(clf_type).casefold())
725
726
  except ValueError as e:
726
- raise ValueError(msg) from e
727
+ raise ValidationError(msg) from e
727
728
 
728
729
  atterberg_lmts = AtterbergLimits(liquid_limit=liquid_limit,
729
730
  plastic_limit=plastic_limit)
@@ -736,8 +737,10 @@ def create_soil_classifier(liquid_limit: float,
736
737
 
737
738
  # USCS classification
738
739
  if not sand:
739
- msg = ErrorMsg("sand must be specified for USCS classification")
740
- raise ValueError(msg)
740
+ msg = ErrorMsg(param_name="sand",
741
+ param_value=sand,
742
+ msg="sand must be specified for USCS classification")
743
+ raise ValidationError(msg)
741
744
 
742
745
  psd = PSD(fines=fines, sand=sand, d_10=d_10, d_30=d_30, d_60=d_60)
743
746
  clf = USCS(atterberg_limits=atterberg_lmts, psd=psd, organic=organic)
@@ -4,10 +4,10 @@ as well as calculating design N-values.
4
4
  """
5
5
  import enum
6
6
  from abc import abstractmethod
7
- from typing import Final, Sequence, Literal
7
+ from typing import Final, Literal, Sequence
8
8
 
9
9
  from .utils import enum_repr, isclose, log10, mean, round_, sqrt, validators
10
- from .utils.exceptions import EnumErrorMsg, ErrorMsg, ValidationError
10
+ from .utils.exceptions import ErrorMsg, ValidationError
11
11
 
12
12
  __all__ = ["SPTNDesign",
13
13
  "HammerType",
@@ -51,14 +51,21 @@ class SPTNDesign:
51
51
  return self._corrected_spt_n_values
52
52
 
53
53
  @corrected_spt_n_values.setter
54
+ @validators.le(100.0)
55
+ @validators.gt(0.0)
54
56
  @validators.min_len(1)
55
57
  def corrected_spt_n_values(self, val: Sequence[float]) -> None:
56
- for v in val:
57
- if v <= 0.0 or v > 100:
58
- raise ValidationError(
59
- "SPT N-values must be between 0.0 and 100.")
60
58
  self._corrected_spt_n_values = val
61
59
 
60
+ @property
61
+ def method(self):
62
+ return self._method
63
+
64
+ @method.setter
65
+ @validators.in_(("min", "avg", "wgt"))
66
+ def method(self, val: str) -> None:
67
+ self._method = val
68
+
62
69
  @staticmethod
63
70
  def _avg_spt_n_design(vals) -> float:
64
71
  return mean(vals)
@@ -105,11 +112,8 @@ class SPTNDesign:
105
112
  return self._min_spt_n_design(self.corrected_spt_n_values)
106
113
  elif self.method == "avg":
107
114
  return self._avg_spt_n_design(self.corrected_spt_n_values)
108
- elif self.method == "wgt":
115
+ else: # method="wgt"
109
116
  return self._wgt_spt_n_design(self.corrected_spt_n_values)
110
- else:
111
- msg = ErrorMsg("method must be 'min', 'avg', or 'wgt'")
112
- raise ValueError(msg)
113
117
 
114
118
 
115
119
  @enum_repr
@@ -227,6 +231,24 @@ class EnergyCorrection:
227
231
  def rod_length(self, val: float) -> None:
228
232
  self._rod_length = val
229
233
 
234
+ @property
235
+ def hammer_type(self) -> HammerType:
236
+ return self._hammer_type
237
+
238
+ @hammer_type.setter
239
+ @validators.in_(tuple(HammerType))
240
+ def hammer_type(self, val: HammerType) -> None:
241
+ self._hammer_type = val
242
+
243
+ @property
244
+ def sampler_type(self) -> SamplerType:
245
+ return self._sampler_type
246
+
247
+ @sampler_type.setter
248
+ @validators.in_(tuple(SamplerType))
249
+ def sampler_type(self, val: SamplerType) -> None:
250
+ self._sampler_type = val
251
+
230
252
  @property
231
253
  def hammer_efficiency(self) -> float:
232
254
  """Hammer efficiency correction factor."""
@@ -558,10 +580,11 @@ def create_overburden_pressure_correction(std_spt_n_value: float, eop,
558
580
  try:
559
581
  opc_type = OPCType(str(opc_type).casefold())
560
582
  except ValueError as e:
561
- msg = EnumErrorMsg(param_name="opc_type",
562
- param_value=opc_type,
563
- param_type=OPCType)
564
- raise ValueError(msg) from e
583
+ msg = ErrorMsg(param_name="opc_type",
584
+ param_value=opc_type,
585
+ symbol="in",
586
+ param_value_bound=list(OPCType))
587
+ raise ValidationError(msg) from e
565
588
 
566
589
  opc_class = _opctypes[opc_type]
567
590
  opc_corr = opc_class(std_spt_n_value=std_spt_n_value, eop=eop)
@@ -0,0 +1,52 @@
1
+ from collections import UserString
2
+ from typing import Any
3
+
4
+
5
+ class _ErrorMsg(UserString):
6
+ def __init__(self, param_name: str = None,
7
+ param_value: Any = None,
8
+ symbol: str = None,
9
+ param_value_bound: Any = None,
10
+ msg: str = None):
11
+ if not msg:
12
+ msg = f"{param_name}: {param_value!r} must be {symbol} {param_value_bound}"
13
+
14
+ self.param_name = param_name
15
+ self.param_value = param_value
16
+ self.symbol = symbol
17
+ self.param_value_bound = param_value_bound
18
+ self.msg = msg
19
+
20
+ super().__init__(msg)
21
+
22
+ def __add__(self, other):
23
+ if isinstance(other, str):
24
+ self.data = self.data + other
25
+ self.msg = self.data
26
+ return self
27
+ return NotImplemented
28
+
29
+ def __radd__(self, other):
30
+ if isinstance(other, str):
31
+ self.data = other + self.data
32
+ self.msg = self.data
33
+ return self
34
+ return NotImplemented
35
+
36
+
37
+ class ErrorMsg(_ErrorMsg):
38
+ pass
39
+
40
+
41
+ class ValidationError(ValueError):
42
+ """Exception raised when a validation error occurs."""
43
+
44
+ def __init__(self, error: ErrorMsg):
45
+ super().__init__(error)
46
+ self.error = error
47
+
48
+
49
+ class SettlementError(ValidationError):
50
+ """Raised when tolerable settlement is greater than the maximum
51
+ allowable settlement.
52
+ """
@@ -0,0 +1,129 @@
1
+ """validators"""
2
+ import operator
3
+ from functools import wraps
4
+ from typing import Any, Callable, Iterable, TypeAlias
5
+
6
+ from .exceptions import ErrorMsg, ValidationError
7
+
8
+ Number: TypeAlias = int | float
9
+
10
+
11
+ class _Validator:
12
+
13
+ def __init__(self, bound: Any, /, *,
14
+ symbol: str,
15
+ func: Callable,
16
+ exc_type: Callable,
17
+ err_msg: str):
18
+ """
19
+
20
+ """
21
+ self.bound = bound
22
+ self.symbol = symbol
23
+ self.func = func
24
+ self.exc_type = exc_type
25
+ self.err_msg = err_msg
26
+
27
+
28
+ class _NumValidator(_Validator):
29
+
30
+ def _check_val(self, v: Number, fname: str):
31
+ if not self.func(v, self.bound):
32
+ msg = ErrorMsg(msg=self.err_msg,
33
+ param_name=fname,
34
+ param_value=v,
35
+ symbol=self.symbol,
36
+ param_value_bound=self.bound)
37
+ raise self.exc_type(msg)
38
+
39
+ def __call__(self, fn):
40
+ @wraps(fn)
41
+ def wrapper(obj, val):
42
+ if isinstance(val, Iterable):
43
+ for v in val:
44
+ self._check_val(v, fn.__name__)
45
+ else:
46
+ self._check_val(val, fn.__name__)
47
+
48
+ fn(obj, val)
49
+
50
+ return wrapper
51
+
52
+
53
+ class _LenValidator(_Validator):
54
+ def _check_val(self, v: Iterable[Any], fname: str):
55
+ if not self.func(len(v), self.bound):
56
+ msg = ErrorMsg(msg=self.err_msg,
57
+ param_name=fname,
58
+ param_value=v,
59
+ symbol=self.symbol,
60
+ param_value_bound=self.bound)
61
+ msg = "Length of " + msg
62
+ raise self.exc_type(msg)
63
+
64
+ def __call__(self, fn):
65
+ @wraps(fn)
66
+ def wrapper(obj, val: Iterable):
67
+ self._check_val(val, fn.__name__)
68
+ fn(obj, val)
69
+
70
+ return wrapper
71
+
72
+
73
+ class _InValidator(_Validator):
74
+ def _check_val(self, v, fname):
75
+ if not self.func(self.bound, v):
76
+ msg = ErrorMsg(msg=self.err_msg,
77
+ param_name=fname,
78
+ param_value=v,
79
+ symbol=self.symbol,
80
+ param_value_bound=self.bound)
81
+ raise self.exc_type(msg)
82
+
83
+ def __call__(self, fn):
84
+ @wraps(fn)
85
+ def wrapper(obj, val):
86
+ self._check_val(val, fn.__name__)
87
+ fn(obj, val)
88
+
89
+ return wrapper
90
+
91
+
92
+ def in_(val: Iterable[Any], /, *, exc_type=ValidationError, err_msg=None):
93
+ return _InValidator(val, symbol="in", func=operator.contains,
94
+ exc_type=exc_type, err_msg=err_msg)
95
+
96
+
97
+ def min_len(val: int, /, *, exc_type=ValidationError, err_msg=None):
98
+ return _LenValidator(val, symbol=">=", func=operator.ge,
99
+ exc_type=exc_type, err_msg=err_msg)
100
+
101
+
102
+ def lt(val: Number, /, *, exc_type=ValidationError, err_msg=None):
103
+ return _NumValidator(val, symbol="<", func=operator.lt,
104
+ exc_type=exc_type, err_msg=err_msg)
105
+
106
+
107
+ def le(val: Number, /, *, exc_type=ValidationError, err_msg=None):
108
+ return _NumValidator(val, symbol="<=", func=operator.le,
109
+ exc_type=exc_type, err_msg=err_msg)
110
+
111
+
112
+ def eq(val: Number, /, *, exc_type=ValidationError, err_msg=None):
113
+ return _NumValidator(val, symbol="==", func=operator.eq,
114
+ exc_type=exc_type, err_msg=err_msg)
115
+
116
+
117
+ def ne(val: Number, /, *, exc_type=ValidationError, err_msg=None):
118
+ return _NumValidator(val, symbol="!=", func=operator.ne,
119
+ exc_type=exc_type, err_msg=err_msg)
120
+
121
+
122
+ def ge(val: Number, /, *, exc_type=ValidationError, err_msg=None):
123
+ return _NumValidator(val, symbol=">=", func=operator.ge,
124
+ exc_type=exc_type, err_msg=err_msg)
125
+
126
+
127
+ def gt(val: Number, /, *, exc_type=ValidationError, err_msg=None):
128
+ return _NumValidator(val, symbol=">", func=operator.gt,
129
+ exc_type=exc_type, err_msg=err_msg)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: geolysis
3
- Version: 0.7.3
3
+ Version: 0.8.0
4
4
  Summary: geolysis is an opensource software for geotechnical engineering analysis and modeling.
5
5
  Author-email: Patrick Boateng <boatengpato.pb@gmail.com>
6
6
  License: MIT License
@@ -134,7 +134,6 @@ Here are brief descriptions of the `geolysis` projects:
134
134
 
135
135
  - [Installation](#installation)
136
136
  - [Usage Example](#usage-example)
137
- - [Features](#features)
138
137
  - [Documentation](#documentation)
139
138
  - [Contributing](#contributing)
140
139
  - [License](#license)
@@ -6,17 +6,20 @@ from geolysis.soil_classifier import (PSD, AtterbergLimits,
6
6
 
7
7
  def test_create_soil_classifier():
8
8
  with pytest.raises(ValueError):
9
+ # Did not provide a classification (clf_type) value
9
10
  create_soil_classifier(liquid_limit=30.4,
10
11
  plastic_limit=15.9,
11
12
  fines=40.20)
12
13
 
13
14
  with pytest.raises(ValueError):
15
+ # Provided a wrong value for clf_type
14
16
  create_soil_classifier(liquid_limit=30.4,
15
17
  plastic_limit=15.9,
16
18
  fines=40.20,
17
19
  clf_type="IS")
18
20
 
19
21
  with pytest.raises(ValueError):
22
+ # Did not provide sand for USCS classification
20
23
  create_soil_classifier(liquid_limit=30.4,
21
24
  plastic_limit=15.9,
22
25
  fines=40.20,
@@ -1,18 +1,18 @@
1
1
  import pytest
2
2
 
3
- from geolysis.spt import (BazaraaPeckOPC, DilatancyCorrection,
4
- EnergyCorrection, GibbsHoltzOPC, HammerType,
5
- LiaoWhitmanOPC, PeckOPC, SamplerType, SkemptonOPC,
6
- SPTNDesign, create_overburden_pressure_correction)
3
+ from geolysis.spt import (DilatancyCorrection, EnergyCorrection, HammerType,
4
+ SamplerType, SPTNDesign,
5
+ create_overburden_pressure_correction)
6
+ from geolysis.utils.exceptions import ValidationError
7
7
 
8
8
 
9
9
  def test_create_spt_correction_errors():
10
- with pytest.raises(ValueError):
10
+ with pytest.raises(ValidationError):
11
11
  create_overburden_pressure_correction(std_spt_n_value=34,
12
12
  eop=100, opc_type="TERZAGHI")
13
13
 
14
14
 
15
- class TestSPTDesign:
15
+ class TestSPTNDesign:
16
16
 
17
17
  def test_spt_n_design(self):
18
18
  spt_design = SPTNDesign([7.0, 15.0, 18], method="min")
@@ -24,20 +24,26 @@ class TestSPTDesign:
24
24
  assert spt_design.n_design() == pytest.approx(9.4)
25
25
 
26
26
  def test_errors(self):
27
- with pytest.raises(ValueError):
27
+ # Provided an empty value for corrected_spt_n_values
28
+ with pytest.raises(ValidationError):
28
29
  SPTNDesign(corrected_spt_n_values=[])
29
30
 
30
- with pytest.raises(ValueError):
31
- spt_design = SPTNDesign(corrected_spt_n_values=[7.0, 15.0, 18],
32
- method="max")
33
- spt_design.n_design()
31
+ # Provided an invalid method
32
+ with pytest.raises(ValidationError):
33
+ SPTNDesign(corrected_spt_n_values=[7.0, 15.0, 18], method="max")
34
34
 
35
- with pytest.raises(ValueError):
35
+ # corrected_spt_n_values is greater than 100
36
+ with pytest.raises(ValidationError):
36
37
  SPTNDesign(corrected_spt_n_values=[22, 44, 120])
37
38
 
38
- with pytest.raises(ValueError):
39
+ # corrected_spt_n_values is 0.0
40
+ with pytest.raises(ValidationError):
39
41
  SPTNDesign(corrected_spt_n_values=[0.0, 15.0, 18])
40
42
 
43
+ # corrected_spt_n_values is less than 0.0
44
+ with pytest.raises(ValidationError):
45
+ SPTNDesign(corrected_spt_n_values=[-10, 15.0, 18])
46
+
41
47
 
42
48
  class TestEnergyCorrection:
43
49
 
@@ -66,6 +72,15 @@ class TestEnergyCorrection:
66
72
  assert energy_corr.standardized_spt_n_value() == pytest.approx(
67
73
  expected)
68
74
 
75
+ def test_errors(self):
76
+ # Provided an invalid value for hammer_type
77
+ with pytest.raises(ValidationError):
78
+ EnergyCorrection(recorded_spt_n_value=22, hammer_type="manual")
79
+
80
+ # Provided an invalid value for sampler_type
81
+ with pytest.raises(ValidationError):
82
+ EnergyCorrection(recorded_spt_n_value=22, sampler_type="std")
83
+
69
84
 
70
85
  class TestGibbsHoltzOPC:
71
86
 
@@ -1,36 +0,0 @@
1
- from typing import Unpack, TypedDict, NotRequired, Any, Optional
2
-
3
-
4
- class _ErrorParams(TypedDict):
5
- param_name: NotRequired[str]
6
- param_value: NotRequired[Any]
7
- param_type: NotRequired[Any]
8
-
9
-
10
- class ErrorMsg(str):
11
-
12
- @staticmethod
13
- def __new__(cls, msg):
14
- return super().__new__(cls, msg)
15
-
16
-
17
- class EnumErrorMsg(ErrorMsg):
18
-
19
- @staticmethod
20
- def __new__(cls, *args, msg: Optional[str] = None,
21
- **kwargs: Unpack[_ErrorParams]):
22
- err_msg = msg if msg else (
23
- f"Invalid value for {kwargs['param_name']}: {kwargs['param_value']}, "
24
- f"Supported types are: {list(kwargs['param_type'])}")
25
-
26
- return super().__new__(cls, err_msg)
27
-
28
-
29
- class ValidationError(ValueError):
30
- """Exception raised when a validation error occurs."""
31
-
32
-
33
- class SettlementError(ValueError):
34
- """Raised when tolerable settlement is greater than the maximum
35
- allowable settlement.
36
- """
@@ -1,101 +0,0 @@
1
- """validators"""
2
- import operator
3
- from typing import Callable, TypeAlias, Optional
4
- from functools import wraps
5
-
6
- from .exceptions import ValidationError
7
-
8
- Number: TypeAlias = int | float
9
-
10
-
11
- def _num_validator(bound: float, /, *,
12
- compare_symbol: str,
13
- compare_fn: Callable,
14
- exc_type: Callable,
15
- err_msg: str):
16
- def dec(fn):
17
- @wraps(fn)
18
- def wrapper(obj, val):
19
- if not compare_fn(val, bound):
20
- msg = f"{fn.__name__} must be {compare_symbol} {bound}"
21
- raise exc_type(err_msg if err_msg else msg)
22
- fn(obj, val)
23
-
24
- return wrapper
25
-
26
- return dec
27
-
28
-
29
- def _len_validator(bound: float, /, *,
30
- compare_symbol: str,
31
- compare_fn: Callable,
32
- exc_type: Callable,
33
- err_msg: str):
34
- def dec(fn):
35
- @wraps(fn)
36
- def wrapper(obj, val):
37
- _len = len(val)
38
- if not compare_fn(_len, bound):
39
- msg = f"Length of '{fn.__name__}' must be {compare_symbol} {bound}"
40
- raise exc_type(err_msg if err_msg else msg)
41
- fn(obj, val)
42
-
43
- return wrapper
44
-
45
- return dec
46
-
47
-
48
- def min_len(m_len: int, /, *,
49
- exc_type=ValidationError,
50
- err_msg: Optional[str] = None):
51
- return _len_validator(m_len, compare_symbol=">=",
52
- compare_fn=operator.ge,
53
- exc_type=exc_type, err_msg=err_msg)
54
-
55
-
56
- def lt(val: Number, /, *, exc_type=ValidationError,
57
- err_msg: Optional[str] = None):
58
- return _num_validator(val, compare_symbol="<",
59
- compare_fn=operator.lt,
60
- exc_type=exc_type,
61
- err_msg=err_msg)
62
-
63
-
64
- def le(val: Number, /, *, exc_type=ValidationError,
65
- err_msg: Optional[str] = None):
66
- return _num_validator(val, compare_symbol="<=",
67
- compare_fn=operator.le,
68
- exc_type=exc_type,
69
- err_msg=err_msg)
70
-
71
-
72
- def eq(val: Number, /, *, exc_type=ValidationError,
73
- err_msg: Optional[str] = None):
74
- return _num_validator(val, compare_symbol="==",
75
- compare_fn=operator.eq,
76
- exc_type=exc_type,
77
- err_msg=err_msg)
78
-
79
-
80
- def ne(val: Number, /, *, exc_type=ValidationError,
81
- err_msg: Optional[str] = None):
82
- return _num_validator(val, compare_symbol="!=",
83
- compare_fn=operator.ne,
84
- exc_type=exc_type,
85
- err_msg=err_msg)
86
-
87
-
88
- def ge(val: Number, /, *, exc_type=ValidationError,
89
- err_msg: Optional[str] = None):
90
- return _num_validator(val, compare_symbol=">=",
91
- compare_fn=operator.ge,
92
- exc_type=exc_type,
93
- err_msg=err_msg)
94
-
95
-
96
- def gt(val: Number, /, *, exc_type=ValidationError,
97
- err_msg: Optional[str] = None):
98
- return _num_validator(val, compare_symbol=">",
99
- compare_fn=operator.gt,
100
- exc_type=exc_type,
101
- err_msg=err_msg)
File without changes
File without changes
File without changes
File without changes