Skip to content

Commit

Permalink
files/inp: fixed inp for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BitterB0NG0 committed Nov 25, 2024
1 parent 21d92e0 commit 656a7c6
Show file tree
Hide file tree
Showing 122 changed files with 1,217 additions and 910 deletions.
10 changes: 5 additions & 5 deletions scripts/build_cell_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ def build_CellOption(cell_option: _data.CellOptionScheme):
o += 'import re\n'
o += 'from typing import Final\n'
o += '\n'
o += 'from ..cell import CellOption, CellKeyword\n'
o += 'from ....utils import types, errors, _parser\n'
o += 'from ..cell_option import CellOption, CellKeyword\n'
o += 'from ...utils import types, errors, _parser\n'
o += '\n'
o += f'class {cell_option.name}(CellOption):\n'
o += ' """\n'
Expand Down Expand Up @@ -137,7 +137,7 @@ def build_CellOption(cell_option: _data.CellOptionScheme):

else:
# value: ?
o += f' {cell_option.attributes[0].name} = {attribute.type}.from_mcnp(tokens.popl())\n'
o += f' {cell_option.attributes[0].name} = {cell_option.attributes[0].type}.from_mcnp(tokens.popl())\n'

o += '\n'

Expand All @@ -156,10 +156,10 @@ def build_CellOption(cell_option: _data.CellOptionScheme):
)
with filename.open('w') as file:
file.write(
f'"""\n Contains the ``{cell_option.name}`` subclass of ``CellOption``."""\n\n'
f'"""\n Contains the ``{cell_option.name}`` subclass of ``CellOption``.\n"""\n\n'
+ build_CellOption(cell_option)
)
init_imports.append(f'from .{cell_option.name} import {cell_option.name}')
init_imports.append(f'from .{cell_option.name.lower()} import {cell_option.name}')
init_all.append(f'"{cell_option.name}",')

init_path = pathlib.Path(__file__).parent / pathlib.Path(
Expand Down
10 changes: 8 additions & 2 deletions scripts/build_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ def build_Data(data: _data.DataScheme):
o += 'from ..data import DataEntry\n' if data.entries else ''
o += 'from ..data import DataOption\n' if data.options else ''
o += 'from ..data import DataKeyword\n' if data.options else ''
o += 'from ....utils import types, errors, _parser\n'
o += 'from ...utils import types, errors, _parser\n'
o += '\n'

# DATA.ENTRY
Expand Down Expand Up @@ -473,6 +473,9 @@ def build_Data(data: _data.DataScheme):
o += '\n'

for attribute in data.attributes:
if attribute.name == 'suffix' or attribute.name == 'designator':
continue

if attribute.type.endswith('Option]'):
# tuple[..Option]

Expand Down Expand Up @@ -571,6 +574,9 @@ def build_Data(data: _data.DataScheme):
o += ' return _parser.Postprocessor.add_continuation_lines(f"{self.mnemonic.to_mcnp()}'

for attribute in data.attributes:
if attribute.name == 'designator' or attribute.name == 'suffix':
continue

if attribute.type.startswith('tuple'):
o += f' {{" ".join(entry.to_mcnp() for entry in self.{attribute.name})}}'
elif attribute.type.startswith('dict'):
Expand All @@ -593,7 +599,7 @@ def build_Data(data: _data.DataScheme):
)
with filename.open('w') as file:
file.write(build_Data(data))
init_imports.append(f'from .{data.name} import {data.name}')
init_imports.append(f'from .{data.name.lower()} import {data.name}')
init_all.append(f'"{data.name}",')

init_path = pathlib.Path(__file__).parent / pathlib.Path(
Expand Down
13 changes: 8 additions & 5 deletions scripts/build_surfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def build_Surface(surface: _data.SurfaceScheme):
o += 'from typing import Final\n'
o += '\n'
o += 'from ..surface import Surface, SurfaceMnemonic\n'
o += 'from ....utils import types, errors, _parser\n'
o += 'from ...utils import types, errors, _parser\n'
o += '\n'
o += f'class {surface.name}(Surface):\n'
o += ' """\n'
Expand Down Expand Up @@ -106,7 +106,9 @@ def build_Surface(surface: _data.SurfaceScheme):
o += f' ``{surface.name}`` object.\n'
o += '\n'
o += ' Raises:\n'
o += ' McnpError: EXPECTED_TOKEN, UNEXPECTED_TOKEN.\n'
o += ' McnpError: EXPECTED_TOKEN.\n'
o += ' McnpError: UNEXPECTED_TOKEN.\n'
o += ' McnpError: UNRECOGNIZED_KEYWORD.\n'
o += ' """\n'
o += '\n'
o += ' source = _parser.Preprocessor.process_inp(source)\n'
Expand Down Expand Up @@ -136,7 +138,8 @@ def build_Surface(surface: _data.SurfaceScheme):
o += ' except Exception:\n'
o += ' transform = None\n'
o += '\n'
o += ' mnemonic = SurfaceMnemonic.from_mcnp(tokens.popl())\n'
o += f' if tokens.popl() != "{surface.mnemonic}":\n'
o += ' raise errors.McnpError(errors.McnpCode.UNRECOGNIZED_KEYWORD, info=source)\n'
o += '\n'

t = []
Expand All @@ -145,7 +148,7 @@ def build_Surface(surface: _data.SurfaceScheme):
t.append(attribute.name)

o += '\n'
o += f' return {surface.name}(number, transform, mnemonic, {", ".join(t)}, is_whiteboundary=is_whiteboundary, is_reflecting=is_reflecting)\n'
o += f' return {surface.name}(number, transform, {", ".join(t)}, is_whiteboundary=is_whiteboundary, is_reflecting=is_reflecting)\n'
o += '\n'

return o
Expand All @@ -160,7 +163,7 @@ def build_Surface(surface: _data.SurfaceScheme):
)
with filename.open('w') as file:
file.write(
f'"""\n Contains the ``{surface.name}`` subclass of ``Surface``."""\n\n'
f'"""\n Contains the ``{surface.name}`` subclass of ``Surface``.\n"""\n\n'
+ build_Surface(surface)
)
init_imports.append(f'from .{surface.name.lower()} import {surface.name}')
Expand Down
Loading

0 comments on commit 656a7c6

Please sign in to comment.