Skip to content

Commit

Permalink
migrate CoordinateReaders
Browse files Browse the repository at this point in the history
  • Loading branch information
jandom committed Aug 20, 2023
1 parent 9727694 commit 60024f4
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 32 deletions.
1 change: 0 additions & 1 deletion doc/source/scripts/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ def get_line(self, *args):
for p in self.preprocess:
self._run_method(p, *args)
for h in self.headings:
print("headings", (h, args))
line.append(self._run_method(h, *args))
for p in self.postprocess:
self._run_method(p, *args)
Expand Down
76 changes: 46 additions & 30 deletions doc/source/scripts/gen_format_overview_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,28 @@
FAIL = ""


class FormatOverview:
def __init__(self) -> None:
def _file_type(fmt, handlers, key):
return base.sphinx_ref(txt=fmt, label=key, suffix="-format")
def _keys(fmt, handlers):
if fmt in DESCRIPTIONS:
key = fmt
else:
key = list(handlers.values())[0].format[0]

# raise an informative error
if key not in DESCRIPTIONS:
key = fmt
return key


def _keys(fmt, handlers):
if fmt in DESCRIPTIONS:
key = fmt
else:
key = list(handlers.values())[0].format[0]
def _file_type(fmt, handlers, key):
return base.sphinx_ref(txt=fmt, label=key, suffix="-format")

# raise an informative error
if key not in DESCRIPTIONS:
key = fmt
return key

def _description(fmt, handlers, key):
return DESCRIPTIONS[key]
def _description(fmt, handlers, key):
return DESCRIPTIONS[key]


class FormatOverview:
def __init__(self) -> None:
def _topology(fmt, handlers, key):
if "Topology parser" in handlers:
return SUCCESS
Expand Down Expand Up @@ -100,23 +103,36 @@ def _write(fmt, handlers, key):
self.table_writer.get_lines_and_write_table()


class CoordinateReaders(FormatOverview):
filename = "formats/coordinate_readers.txt"
include_table = "Table of supported coordinate readers and the information read"
headings = ["File type", "Description", "Velocities", "Forces"]

def _set_up_input(self):
return [(x, y) for x, y in sorted_types if "Coordinate reader" in y]
class CoordinateReaders:
def __init__(self) -> None:
def _velocities(fmt, handlers, key):
if handlers["Coordinate reader"].units.get("velocity", None):
return SUCCESS
return FAIL

def _velocities(self, fmt, handlers):
if handlers["Coordinate reader"].units.get("velocity", None):
return SUCCESS
return FAIL
def _forces(fmt, handlers, key):
if handlers["Coordinate reader"].units.get("force", None):
return SUCCESS
return FAIL

def _forces(self, fmt, handlers):
if handlers["Coordinate reader"].units.get("force", None):
return SUCCESS
return FAIL
input_items = [
(format, handlers, _keys(format, handlers))
for format, handlers in sorted_types
if "Coordinate reader" in handlers
]
self.table_writer = TableWriter(
filename="formats/coordinate_readers.txt",
include_table="Table of supported coordinate readers and the information read",
headings=["File type", "Description", "Velocities", "Forces"],
input_items=input_items,
columns={
"File type": _file_type,
"Description": _description,
"Velocities": _velocities,
"Forces": _forces,
},
)
self.table_writer.get_lines_and_write_table()


class SphinxClasses(TableWriter):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_FormatOverview(snapshot):
def test_CoordinateReaders(snapshot):
with patch("builtins.open"):
cr = CoordinateReaders()
assert cr.lines == snapshot
assert cr.table_writer.lines == snapshot


def test_SphinxClasses(snapshot):
Expand Down

0 comments on commit 60024f4

Please sign in to comment.