Skip to content

Commit 473ddc0

Browse files
committed
tests: fixed inp converage
1 parent dc75c53 commit 473ddc0

File tree

1,288 files changed

+41151
-36744
lines changed

Some content is hidden

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

1,288 files changed

+41151
-36744
lines changed

docs/source/pymcnp/inp/cell.md

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -128,17 +128,10 @@
128128
:members:
129129
```
130130

131-
### ``Tmp_0`` Class
131+
### ``Tmp`` Class
132132

133133
```{eval-rst}
134-
.. autoclass:: pymcnp.inp.cell.Tmp_0
135-
:members:
136-
```
137-
138-
### ``Tmp_1`` Class
139-
140-
```{eval-rst}
141-
.. autoclass:: pymcnp.inp.cell.Tmp_1
134+
.. autoclass:: pymcnp.inp.cell.Tmp
142135
:members:
143136
```
144137

@@ -340,17 +333,10 @@
340333
:members:
341334
```
342335

343-
### ``TmpBuilder_0`` Class
344-
345-
```{eval-rst}
346-
.. autoclass:: pymcnp.inp.cell.TmpBuilder_0
347-
:members:
348-
```
349-
350-
### ``TmpBuilder_1`` Class
336+
### ``TmpBuilder`` Class
351337

352338
```{eval-rst}
353-
.. autoclass:: pymcnp.inp.cell.TmpBuilder_1
339+
.. autoclass:: pymcnp.inp.cell.TmpBuilder
354340
:members:
355341
```
356342

docs/source/pymcnp/inp/data.md

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,13 @@
8080

8181
[bfld subpackage](data/bfld)
8282

83-
### ``C_0`` Class
83+
### ``C`` Class
8484

8585
```{eval-rst}
86-
.. autoclass:: pymcnp.inp.data.C_0
86+
.. autoclass:: pymcnp.inp.data.C
8787
:members:
8888
```
8989

90-
### ``C_1`` Class
91-
92-
```{eval-rst}
93-
.. autoclass:: pymcnp.inp.data.C_1
94-
:members:
95-
```
9690

9791
### ``Cf`` Class
9892

@@ -911,6 +905,20 @@
911905
:members:
912906
```
913907

908+
### ``Tf_0`` Class
909+
910+
```{eval-rst}
911+
.. autoclass:: pymcnp.inp.data.Tf_0
912+
:members:
913+
```
914+
915+
### ``Tf_1`` Class
916+
917+
```{eval-rst}
918+
.. autoclass:: pymcnp.inp.data.Tf_1
919+
:members:
920+
```
921+
914922
### ``Tm`` Class
915923

916924
```{eval-rst}

docs/source/pymcnp/inp/data/stop.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@
3232
:members:
3333
```
3434

35-
### ``FkBuilder`` Class
35+
### ``FBuilder`` Class
3636

3737
```{eval-rst}
38-
.. autoclass:: pymcnp.inp.data.stop.FkBuilder
38+
.. autoclass:: pymcnp.inp.data.stop.FBuilder
3939
:members:
4040
```
4141

examples/example_box.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,9 @@ def get_inp(radius_air, radius_shield, radius_lead):
1111

1212
cell_air = pymcnp.CellBuilder(number=1, material=21, density=0.5, geometry=geometry_air)
1313

14-
cell_shield = pymcnp.CellBuilder(
15-
number=2, material=22, density=0.5, geometry=geometry_shield & geometry_air
16-
)
14+
cell_shield = pymcnp.CellBuilder(number=2, material=22, density=0.5, geometry=geometry_shield & geometry_air)
1715

18-
cell_lead = pymcnp.CellBuilder(
19-
number=3, material=23, density=0.5, geometry=geometry_lead & geometry_shield
20-
)
16+
cell_lead = pymcnp.CellBuilder(number=3, material=23, density=0.5, geometry=geometry_lead & geometry_shield)
2117

2218
cell_world = pymcnp.CellBuilder(number=4, material=0, geometry=geometry_world)
2319

@@ -52,15 +48,9 @@ def get_inp(radius_air, radius_shield, radius_lead):
5248
inp.append(surface_lead)
5349
inp.append(surface_world)
5450

55-
material_air = pymcnp.DataBuilder.unbuild(
56-
pymcnp.inp.Data(pymcnp.inp.data.M.from_formula(21, {'N2': 0.8, 'O2': 0.2}))
57-
)
58-
material_shield = pymcnp.DataBuilder.unbuild(
59-
pymcnp.inp.Data(pymcnp.inp.data.M.from_formula(22, {'TiO2': 0.5, 'PbO': 0.5}))
60-
)
61-
material_lead = pymcnp.DataBuilder.unbuild(
62-
pymcnp.inp.Data(pymcnp.inp.data.M.from_formula(23, {'Pb': 1}))
63-
)
51+
material_air = pymcnp.DataBuilder.unbuild(pymcnp.inp.Data(pymcnp.inp.data.M.from_formula(21, {'N2': 0.8, 'O2': 0.2})))
52+
material_shield = pymcnp.DataBuilder.unbuild(pymcnp.inp.Data(pymcnp.inp.data.M.from_formula(22, {'TiO2': 0.5, 'PbO': 0.5})))
53+
material_lead = pymcnp.DataBuilder.unbuild(pymcnp.inp.Data(pymcnp.inp.data.M.from_formula(23, {'Pb': 1})))
6454

6555
sdef = pymcnp.DataBuilder(
6656
mnemonic='sdef',

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ where = ["./src"]
6262
write_to = "./src/pymcnp/version.py"
6363

6464
[tool.ruff]
65-
line-length = 100
65+
line-length = 200
6666
lint.ignore = ["E741", "E742"]
6767

6868
[tool.ruff.format]

scripts/inp_code.py

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,9 @@ def ATTRS_DATACLASS(element, t):
8888
if attribute.optional:
8989
if attribute.type.startswith('types.Tuple'):
9090
if 'types.Integer' in attribute.type:
91-
b += [
92-
f'{attribute.name}: list[str] | list[int] | list[{attribute.type[12:-1]}] = None'
93-
]
91+
b += [f'{attribute.name}: list[str] | list[int] | list[{attribute.type[12:-1]}] = None']
9492
elif 'types.Real' in attribute.type:
95-
b += [
96-
f'{attribute.name}: list[str] | list[float] | list[{attribute.type[12:-1]}] = None'
97-
]
93+
b += [f'{attribute.name}: list[str] | list[float] | list[{attribute.type[12:-1]}] = None']
9894
else:
9995
b += [f'{attribute.name}: list[str] | list[{attribute.type[12:-1]}] = None']
10096
else:
@@ -107,13 +103,9 @@ def ATTRS_DATACLASS(element, t):
107103
else:
108104
if attribute.type.startswith('types.Tuple'):
109105
if 'types.Integer' in attribute.type:
110-
a += [
111-
f'{attribute.name}: list[str] | list[int] | list[{attribute.type[12:-1]}]'
112-
]
106+
a += [f'{attribute.name}: list[str] | list[int] | list[{attribute.type[12:-1]}]']
113107
elif 'types.Real' in attribute.type:
114-
a += [
115-
f'{attribute.name}: list[str] | list[float] | list[{attribute.type[12:-1]}]'
116-
]
108+
a += [f'{attribute.name}: list[str] | list[float] | list[{attribute.type[12:-1]}]']
117109
else:
118110
a += [f'{attribute.name}: list[str] | list[{attribute.type[12:-1]}]']
119111
else:
@@ -141,7 +133,7 @@ def ATTRS_LIST(element):
141133
o = ''
142134

143135
for attribute in element.attributes:
144-
if attribute.name not in {'suffix', 'designator'}:
136+
if attribute.name not in {'suffix', 'designator', 'prefix'}:
145137
o += f'{attribute.name}, '
146138

147139
return o
@@ -209,27 +201,28 @@ def ATTRS_BUILDER(element, t):
209201
o += f'{TABS(t)} if isinstance(item, {attribute.type[12:-1]}):\n'
210202
o += f'{TABS(t)} {attribute.name}.append(item)\n'
211203
o += f'{TABS(t)} elif isinstance(item, int):\n'
212-
o += (
213-
f'{TABS(t)} {attribute.name}.append({attribute.type[12:-1]}(item))\n'
214-
)
204+
o += f'{TABS(t)} {attribute.name}.append({attribute.type[12:-1]}(item))\n'
215205
o += f'{TABS(t)} elif isinstance(item, str):\n'
216206
o += f'{TABS(t)} {attribute.name}.append({attribute.type[12:-1]}.from_mcnp(item))\n'
217207
elif 'types.Real' in attribute.type:
218208
o += f'{TABS(t)} if isinstance(item, {attribute.type[12:-1]}):\n'
219209
o += f'{TABS(t)} {attribute.name}.append(item)\n'
220210
o += f'{TABS(t)} elif isinstance(item, float) or isinstance(item, int):\n'
221-
o += (
222-
f'{TABS(t)} {attribute.name}.append({attribute.type[12:-1]}(item))\n'
223-
)
211+
o += f'{TABS(t)} {attribute.name}.append({attribute.type[12:-1]}(item))\n'
224212
o += f'{TABS(t)} elif isinstance(item, str):\n'
225213
o += f'{TABS(t)} {attribute.name}.append({attribute.type[12:-1]}.from_mcnp(item))\n'
226-
else:
214+
elif 'Option' in attribute.type:
227215
o += f'{TABS(t)} if isinstance(item, {attribute.type[12:-1]}):\n'
228216
o += f'{TABS(t)} {attribute.name}.append(item)\n'
229217
o += f'{TABS(t)} elif isinstance(item, str):\n'
230218
o += f'{TABS(t)} {attribute.name}.append({attribute.type[12:-1]}.from_mcnp(item))\n'
231-
o += f'{TABS(t)} else:\n'
219+
o += f'{TABS(t)} elif isinstance(item, {element.name}{CAMEL(attribute.type[12+len(element.name):-1], "Builder")}):\n'
232220
o += f'{TABS(t)} {attribute.name}.append(item.build())\n'
221+
else:
222+
o += f'{TABS(t)} if isinstance(item, {attribute.type[12:-1]}):\n'
223+
o += f'{TABS(t)} {attribute.name}.append(item)\n'
224+
o += f'{TABS(t)} elif isinstance(item, str):\n'
225+
o += f'{TABS(t)} {attribute.name}.append({attribute.type[12:-1]}.from_mcnp(item))\n'
233226
o += f'{TABS(t)} {attribute.name} = types.Tuple({attribute.name})\n'
234227
o += f'{TABS(t)}else:\n'
235228
o += f'{TABS(t)} {attribute.name} = None\n'
@@ -249,6 +242,13 @@ def ATTRS_BUILDER(element, t):
249242
o += f'{TABS(t)} {attribute.name} = {attribute.type}(self.{attribute.name})\n'
250243
o += f'{TABS(t)}elif isinstance(self.{attribute.name}, str):\n'
251244
o += f'{TABS(t)} {attribute.name} = {attribute.type}.from_mcnp(self.{attribute.name})\n'
245+
elif 'Option' in attribute.type:
246+
o += f'{TABS(t)}if isinstance(self.{attribute.name}, {attribute.type}):\n'
247+
o += f'{TABS(t)} {attribute.name} = self.{attribute.name}\n'
248+
o += f'{TABS(t)}elif isinstance(self.{attribute.name}, str):\n'
249+
o += f'{TABS(t)} {attribute.name} = {attribute.type}.from_mcnp(self.{attribute.name})\n'
250+
o += f'{TABS(t)}elif isinstance(self.{attribute.name}, {element.name}{CAMEL(attribute.type[len(element.name):], "Builder")}):\n'
251+
o += f'{TABS(t)} {attribute.name} = self.{attribute.name}.build()\n'
252252
else:
253253
o += f'{TABS(t)}if isinstance(self.{attribute.name}, {attribute.type}):\n'
254254
o += f'{TABS(t)} {attribute.name} = self.{attribute.name}\n'
@@ -273,10 +273,7 @@ def ATTRS_UNBUILDER(element, t):
273273
o = ''
274274

275275
for attribute in element.attributes:
276-
if attribute.type.startswith('types.'):
277-
o += f'{TABS(t)}{attribute.name}=copy.deepcopy(ast.{attribute.name}),\n'
278-
else:
279-
o += f'{TABS(t)}{attribute.name}={CAMEL(attribute.type, "Builder")}.unbuild(ast.{attribute.name}),\n'
276+
o += f'{TABS(t)}{attribute.name}=copy.deepcopy(ast.{attribute.name}),\n'
280277

281278
return o.strip()
282279

@@ -285,12 +282,14 @@ def ATTRS_UNBUILDER(element, t):
285282
def INIT(element):
286283
return f"""
287284
from ._option import {CAMEL(element.name, "Option")}
285+
from ._option import {CAMEL(element.name, "OptionBuilder")}
288286
{''.join(f"from . import {SNAKE(option.name)}\n" if option.options else "" for option in element.options)[:-1]}
289287
{''.join(f'from .{CAMEL(option.name)} import {CAMEL(option.name)}\n' for option in element.options)[:-1]}
290288
{''.join(f'from .{CAMEL(option.name)} import {CAMEL(option.name, "Builder")}\n' for option in element.options)[:-1]}
291289
292290
__all__ = [
293291
"{CAMEL(element.name, "Option")}",
292+
"{CAMEL(element.name, "OptionBuilder")}",
294293
{''.join(f'\t"{SNAKE(option.name)}",\n' if option.options else "" for option in element.options).strip()}
295294
{''.join(f'\t"{CAMEL(option.name)}",\n' for option in element.options).strip()}
296295
{''.join(f'\t"{CAMEL(option.name, "Builder")}",\n' for option in element.options).strip()}
@@ -304,18 +303,24 @@ def OPTION(element, depth):
304303
import typing
305304
306305
{''.join(f"from . import {SNAKE(option.name)}\n" if option.options else "" for option in element.options)}
307-
from {"." * (depth - 1)}_option import Option
306+
from {"." * (depth - 1)} import _option
308307
from {"." * depth}utils import types
309308
from {"." * depth}utils import errors
310309
from {"." * depth}utils import _parser
311-
from {"." * depth}utils import _object
312310
313311
314-
class {CAMEL(element.name, "Option")}(Option):
312+
class {CAMEL(element.name, "Option")}(_option.Option):
315313
"""
316314
Represents generic INP {element.name} options.
317315
"""
318316
317+
pass
318+
319+
class {CAMEL(element.name, "OptionBuilder")}(_option.OptionBuilder):
320+
"""
321+
Represents generic INP {element.name} option builders.
322+
"""
323+
319324
pass
320325
'''[1:]
321326

@@ -330,15 +335,15 @@ def ELEMENT(element, parent_name, depth):
330335
import molmass
331336
332337
{f"from . import {SNAKE(element.name)}" if element.options else ""}
333-
{f"from ._option import {CAMEL(parent_name, 'Option')}" if parent_name else "from ._card import Card"}
338+
{"from . import _option" if parent_name else "from . import _card"}
334339
from {"." * depth}utils import types
335340
from {"." * depth}utils import errors
336341
from {"." * depth}utils import _parser
337342
from {"." * depth}utils import _elements
338343
from {"." * depth}utils import _visualization
339344
340345
341-
class {CAMEL(element.name)}({CAMEL(parent_name, 'Option')}):
346+
class {CAMEL(element.name)}(_option.{CAMEL(parent_name, 'Option')}):
342347
"""
343348
Represents INP {element.name.split('_')[0]}{f" variation #{element.name.split('_')[1]}"if len(element.name.split('_')) - 1 else ""} elements.
344349
@@ -370,7 +375,7 @@ def __init__(self, {ATTRS_PARAM(element)}):
370375
371376
{element.extra.strip()}
372377
@dataclasses.dataclass
373-
class {CAMEL(element.name, "Builder")}:
378+
class {CAMEL(element.name, "Builder")}(_option.{CAMEL(parent_name, 'OptionBuilder')}):
374379
"""
375380
Builds ``{CAMEL(element.name)}``.
376381
@@ -403,7 +408,7 @@ def unbuild(ast: {CAMEL(element.name)}):
403408
``{CAMEL(element.name, "Builder")}`` for ``{CAMEL(element.name)}``.
404409
"""
405410
406-
return {CAMEL(element.name)}(
411+
return {CAMEL(element.name, "Builder")}(
407412
{ATTRS_UNBUILDER(element, 3)}
408413
)
409414
'''[1:]
@@ -433,6 +438,4 @@ def build_element(element, parent_name, path_dir, depth):
433438

434439

435440
for card in inp_data.cards.options:
436-
build_element(
437-
card, 'alsdkjfhalsdkjf', pathlib.Path(__file__).parent.parent / 'src/pymcnp/inp', 3
438-
)
441+
build_element(card, 'alsdkjfhalsdkjf', pathlib.Path(__file__).parent.parent / 'src/pymcnp/inp', 3)

0 commit comments

Comments
 (0)