Skip to content

Commit

Permalink
migrate TopologyAttrs
Browse files Browse the repository at this point in the history
  • Loading branch information
jandom committed Aug 20, 2023
1 parent 3858aa6 commit 828ed6c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
43 changes: 24 additions & 19 deletions doc/source/scripts/gen_topologyparser_attrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,30 +142,35 @@ def _get_attrs(line, format, parser, expected, guessed, key_label):
self.attrs = attrs


class TopologyAttrs(TableWriter):
headings = ("Atom", "AtomGroup", "Description", "Supported formats")
filename = "generated/topology/topologyattrs.txt"

class TopologyAttrs:
def __init__(self, attrs):
self.attrs = attrs
super(TopologyAttrs, self).__init__()

def _set_up_input(self):
return sorted(
[x, *y] for x, y in NON_CORE_ATTRS.items() if x not in MANDATORY_ATTRS
)
def _atom(name, singular, *args):
return singular

def _atom(self, name, singular, *args):
return singular
def _atomgroup(name, *args):
return name

def _atomgroup(self, name, *args):
return name
def _description(name, singular, description):
return description

def _description(self, name, singular, description):
return description
def _supported_formats(name, singular, description):
return ", ".join(sorted(attrs[name]))

def _supported_formats(self, name, singular, description):
return ", ".join(sorted(self.attrs[name]))
input_items = sorted(
[x, *y] for x, y in NON_CORE_ATTRS.items() if x not in MANDATORY_ATTRS
)
self.table_writer = TableWriter(
headings=("Atom", "AtomGroup", "Description", "Supported formats"),
filename="generated/topology/topologyattrs.txt",
input_items=input_items,
columns={
"Atom": _atom,
"AtomGroup": _atomgroup,
"Description": _description,
"Supported formats": _supported_formats,
},
)
self.table_writer.get_lines_and_write_table()


class ConnectivityAttrs(TopologyAttrs):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def test_TopologyAttrs(snapshot):
with patch("builtins.open"):
top = TopologyParsers()
ta = TopologyAttrs(top.attrs)
assert ta.lines == snapshot
assert ta.table_writer.lines == snapshot


def test_ConnectivityAttrs(snapshot):
Expand Down

0 comments on commit 828ed6c

Please sign in to comment.