Skip to content

Commit d06f82b

Browse files
committed
types: fixed coverage
1 parent 9904084 commit d06f82b

42 files changed

Lines changed: 3274 additions & 548 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

scripts/inp_data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6188,7 +6188,7 @@ def from_formula(number: int, formulas: dict[str, float], is_weight: bool = True
61886188
],
61896189
),
61906190
ElementScheme(
6191-
name='tme_0',
6191+
name='tme_1',
61926192
mnemonic='tme',
61936193
attributes=[
61946194
AttributeScheme(

src/pymcnp/Ptrac.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ class Ptrac(_object.McnpFile):
1616
histories: PTRAC histories.
1717
"""
1818

19-
_REGEX = re.compile(r'\A( -1\n.{60}\n[^\n]{80}\n(?:\s[^\n]{120}\n)+\s[^\n]{100}\n(?:\s(?:[^\n]{4})+\n)+?)((?:[^\n]+\n(?:(?:(?:(?:\s[^\n]{50})|(?:\s[^\n]{60})|(?:\s[^\n]{60})|(?:\s[^\n]{70})|(?:\s[^\n]{60})|(?:\s[^\n]{70})|(?:\s[^\n]{70})|(?:\s[^\n]{80}))\n(?:\s[^\n]{39})|(?:\s[^\n]{117}))\n)+)+)\Z')
19+
_REGEX = re.compile(
20+
r'\A( -1\n.{60}\n[^\n]{80}\n(?:\s[^\n]{120}\n)+\s[^\n]{100}\n(?:\s(?:[^\n]{4})+\n)+?)((?:[^\n]+\n(?:(?:(?:(?:\s[^\n]{50})|(?:\s[^\n]{60})|(?:\s[^\n]{60})|(?:\s[^\n]{70})|(?:\s[^\n]{60})|(?:\s[^\n]{70})|(?:\s[^\n]{70})|(?:\s[^\n]{80}))\n(?:\s[^\n]{39})|(?:\s[^\n]{117}))\n)+)+)\Z'
21+
)
2022

2123
def __init__(self, header: ptrac.Header, histories: typing.Generator[ptrac.History, None, None]):
2224
"""

src/pymcnp/inp/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from . import _card
1+
from ._card import Card
22
from ._option import Option
33
from . import cell
44
from . import like

src/pymcnp/inp/data/sdef/Tme_1.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import re
22

3+
from . import tme_1
34
from . import _option
4-
from .... import types
55
from .... import errors
66

77

@@ -13,12 +13,12 @@ class Tme_1(_option.SdefOption):
1313
_KEYWORD = 'tme'
1414

1515
_ATTRS = {
16-
'time': types.EmbeddedDistribution,
16+
'time': tme_1.Embedded,
1717
}
1818

19-
_REGEX = re.compile(rf'\Atme( {types.EmbeddedDistribution._REGEX.pattern[2:-2]})\Z')
19+
_REGEX = re.compile(rf'\Atme( {tme_1.Embedded._REGEX.pattern[2:-2]})\Z')
2020

21-
def __init__(self, time: str | types.EmbeddedDistribution):
21+
def __init__(self, time: str | tme_1.Embedded):
2222
"""
2323
Initializes ``Tme_1``.
2424
@@ -29,10 +29,10 @@ def __init__(self, time: str | types.EmbeddedDistribution):
2929
InpError: SEMANTICS_OPTION.
3030
"""
3131

32-
self.time: types.EmbeddedDistribution = time
32+
self.time: tme_1.Embedded = time
3333

3434
@property
35-
def time(self) -> types.EmbeddedDistribution:
35+
def time(self) -> tme_1.Embedded:
3636
"""
3737
Time in shakes
3838
@@ -44,7 +44,7 @@ def time(self) -> types.EmbeddedDistribution:
4444
return self._time
4545

4646
@time.setter
47-
def time(self, time: str | types.EmbeddedDistribution) -> None:
47+
def time(self, time: str | tme_1.Embedded) -> None:
4848
"""
4949
Sets ``time``.
5050
@@ -57,12 +57,12 @@ def time(self, time: str | types.EmbeddedDistribution) -> None:
5757
"""
5858

5959
if time is not None:
60-
if isinstance(time, types.EmbeddedDistribution):
60+
if isinstance(time, tme_1.Embedded):
6161
time = time
6262
elif isinstance(time, str):
63-
time = types.EmbeddedDistribution.from_mcnp(time)
63+
time = tme_1.Embedded.from_mcnp(time)
6464

6565
if time is None:
6666
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION, time)
6767

68-
self._time: types.EmbeddedDistribution = time
68+
self._time: tme_1.Embedded = time

src/pymcnp/inp/data/sdef/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from ._option import SdefOption
22

3+
from . import tme_1
34
from .Cel import Cel
45
from .Sur import Sur
56
from .Erg_0 import Erg_0
@@ -32,6 +33,7 @@
3233

3334
__all__ = [
3435
'SdefOption',
36+
'tme_1',
3537
'Cel',
3638
'Sur',
3739
'Erg_0',
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import re
2+
3+
from . import _entry
4+
from ..... import types
5+
from ..... import errors
6+
7+
8+
class Embedded(_entry.TmeEntry_1):
9+
"""
10+
Represents INP embedded distribution entries.
11+
12+
Attributes:
13+
distributions: Distribution distributions.
14+
"""
15+
16+
_REGEX = re.compile(rf'\A({types.Distribution._REGEX.pattern[2:-2]}(?: ?< ?{types.Distribution._REGEX.pattern[2:-2]})*)\Z')
17+
18+
def __init__(self, distributions: types.Tuple[types.Distribution]):
19+
"""
20+
Initializes ``Embedded``.
21+
22+
Parameters:
23+
distributions: Time distributions.
24+
25+
Raises:
26+
TypesError: SEMANTICS_TYPE.
27+
"""
28+
29+
if distributions is None or None in distributions:
30+
raise errors.TypesError(errors.TypesCode.SEMANTICS_TYPE, distributions)
31+
32+
self.distributions: types.Tuple[types.Distribution] = distributions
33+
34+
@staticmethod
35+
def from_mcnp(source: str):
36+
"""
37+
Generates ``Embedded`` from MCNP.
38+
39+
Parameters:
40+
source: MCNP for ``Embedded``.
41+
42+
Returns:
43+
``Embedded`` object.
44+
45+
Raises:
46+
TypesError: SYNTAX_TYPE.
47+
"""
48+
49+
tokens = Embedded._REGEX.match(source)
50+
51+
if not tokens:
52+
raise errors.TypesError(errors.TypesCode.SYNTAX_TYPE, source)
53+
54+
distributions = types.Tuple([types.Distribution.from_mcnp(token.strip()) for token in source.split('<')])
55+
56+
return Embedded(distributions)
57+
58+
def to_mcnp(self):
59+
"""
60+
Generates MCNP from ``Embedded``.
61+
62+
Returns:
63+
MCNP for ``Embedded``.
64+
"""
65+
66+
return '<'.join(number.to_mcnp() for number in self.distributions)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from ._entry import TmeEntry_1
2+
from .Embedded import Embedded
3+
4+
__all__ = [
5+
'TmeEntry_1',
6+
'Embedded',
7+
]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from .... import _entry
2+
3+
4+
class TmeEntry_1(_entry.Entry):
5+
"""
6+
Represents generic INP tme entries.
7+
"""
8+
9+
pass

0 commit comments

Comments
 (0)