Skip to content

Commit

Permalink
Fix some miscellaneous issues breaking expectations/tests
Browse files Browse the repository at this point in the history
  • Loading branch information
oerc0122 committed Nov 28, 2024
1 parent 4259ec3 commit b94edfd
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 23 deletions.
2 changes: 1 addition & 1 deletion castep_outputs/cli/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def parse_args(to_parse: Sequence[str] = ()) -> argparse.Namespace:
Examples
--------
>>> parse_args()
parse_args()
"""
args = ARG_PARSER.parse_args()

Expand Down
1 change: 1 addition & 0 deletions castep_outputs/cli/castep_outputs_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ def parse_all(
elif isinstance(output, io.TextIOBase):
file_dumper(data, output)
else:
output = Path(output)
with output.open("a+", encoding="utf-8") as out_file:
file_dumper(data, out_file)

Expand Down
42 changes: 22 additions & 20 deletions castep_outputs/parsers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,28 @@
from .ts_file_parser import parse_ts_file
from .xrd_sf_file_parser import parse_xrd_sf_file

__all__ = ["parse_castep_file",
"parse_cell_param_file",
"parse_cell_param_file",
"parse_md_geom_file",
"parse_md_geom_file",
"parse_bands_file",
"parse_hug_file",
"parse_phonon_dos_file",
"parse_efield_file",
"parse_xrd_sf_file",
"parse_elf_fmt_file",
"parse_chdiff_fmt_file",
"parse_pot_fmt_file",
"parse_den_fmt_file",
"parse_elastic_file",
"parse_ts_file",
"parse_magres_file",
"parse_tddft_file",
"parse_err_file",
"parse_phonon_file"]
__all__ = [
"parse_bands_file",
"parse_castep_file",
"parse_cell_param_file",
"parse_cell_param_file",
"parse_chdiff_fmt_file",
"parse_den_fmt_file",
"parse_efield_file",
"parse_elastic_file",
"parse_elf_fmt_file",
"parse_err_file",
"parse_hug_file",
"parse_magres_file",
"parse_md_geom_file",
"parse_md_geom_file",
"parse_phonon_dos_file",
"parse_phonon_file",
"parse_pot_fmt_file",
"parse_tddft_file",
"parse_ts_file",
"parse_xrd_sf_file",
]


#: Dictionary of available parsers.
Expand Down
14 changes: 12 additions & 2 deletions castep_outputs/utilities/filewrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def get_lines(
*,
eof_possible: bool = False,
) -> Block:
"""
r"""
Read the next `n_lines` from `in_file` and return the block.
Parameters
Expand All @@ -133,14 +133,24 @@ def get_lines(
------
IOError
If EOF reached and ``not eof_possible``.
Examples
--------
>>> from io import StringIO
>>> x = StringIO('Hello\nThere\nFriend')
>>> block = Block.get_lines(x, 2)
>>> type(block).__name__
'Block'
>>> block.aslist()
['Hello\n', 'There\n']
"""
block = cls(in_file)

data: list[str] = []
for i, line in enumerate(in_file, 1):
if i > n_lines:
break
data += line
data.append(line)
else:
if not eof_possible:
if hasattr(in_file, "name"):
Expand Down

0 comments on commit b94edfd

Please sign in to comment.