Skip to content

Commit

Permalink
TST: update expected output in test_repr_str, physical_types cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dhomeier committed Aug 13, 2021
1 parent 1b87493 commit 28caae7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
8 changes: 4 additions & 4 deletions ndcube/extra_coords/extra_coords.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,15 +393,15 @@ def dropped_world_dimensions(self):

def __str__(self):
classname = self.__class__.__name__
elements = [f"{', '.join(table.names)} ({axes}) {table.physical_types}: {table}"
for axes, table in self._lookup_tables]
length = len(classname) + 2 * len(elements) + sum(len(e) for e in elements)
elm = [f"{', '.join(table.names)} ({axes}) {table.physical_types or '[undefined]'}: {table}"
for axes, table in self._lookup_tables]
length = len(classname) + 2 * len(elm) + sum(len(e) for e in elm)
if length > np.get_printoptions()['linewidth']:
joiner = ',\n ' + len(classname) * ' '
else:
joiner = ', '

return f"{classname}({joiner.join(elements)})"
return f"{classname}({joiner.join(elm)})"

def __repr__(self):
return f"{object.__repr__(self)}\n{self}"
10 changes: 5 additions & 5 deletions ndcube/extra_coords/table_coord.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,12 @@ def __and__(self, other):
return MultipleTableCoordinate(self, other)

def __str__(self):
header = f"{self.__class__.__name__} [{self.physical_types}]:"
content = str(self.table).lstrip('(').rstrip(',)')
if len(header) + len(content) >= np.get_printoptions()['linewidth']:
return '\n'.join((header, content))
h = f"{self.__class__.__name__} {self.names or ''} {self.physical_types or '[undefined]'}:"
c = str(self.table).lstrip('(').rstrip(',)')
if len(h) + len(c) >= np.get_printoptions()['linewidth']:
return '\n'.join((h, c))
else:
return ' '.join((header, content))
return ' '.join((h, c))

def __repr__(self):
return f"{object.__repr__(self)}\n{self}"
Expand Down
5 changes: 3 additions & 2 deletions ndcube/extra_coords/tests/test_lookup_table_coord.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,9 @@ def test_repr_str(lut_1d_time, lut_1d_wave):

join = lut_1d_time & lut_1d_wave
assert str(lut_1d_time.table) in str(join)
assert str(lut_1d_wave.table) in str(join)
assert "TimeTableCoordinate" not in repr(join)
assert str(lut_1d_wave.table)[1:-2] in str(join)
assert "TimeTableCoordinate" in repr(join)
assert "QuantityTableCoordinate" in repr(join)
assert "MultipleTableCoordinate" in repr(join)


Expand Down
8 changes: 4 additions & 4 deletions ndcube/global_coords.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,15 @@ def __len__(self):

def __str__(self):
classname = self.__class__.__name__
elements = [f"{name} ['{ptype}']:\n{repr(coord)}" for (name, coord), ptype in
zip(self.items(), self.physical_types.values())]
length = len(classname) + 2 * len(elements) + sum(len(e) for e in elements)
elm = [f"{name} ['{ptype or ['undefined']}']:\n{repr(coord)}" for (name, coord), ptype in
zip(self.items(), self.physical_types.values())]
length = len(classname) + 2 * len(elm) + sum(len(e) for e in elm)
if length > np.get_printoptions()['linewidth']:
joiner = ',\n ' + len(classname) * ' '
else:
joiner = ', '

return f"{classname}({joiner.join(elements)})"
return f"{classname}({joiner.join(elm)})"

def __repr__(self):
return f"{object.__repr__(self)}\n{str(self)}"

0 comments on commit 28caae7

Please sign in to comment.