Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 FIX: Add __str__ method to Orbital Class #4829

Merged
merged 5 commits into from Mar 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions aiida/tools/data/orbital/orbital.py
Expand Up @@ -112,6 +112,12 @@ def __init__(self, **kwargs):
def __repr__(self):
return f'<{self.__class__.__name__}: {str(self)}>'

def __str__(self) -> str:
orb_dict = self.get_orbital_dict()

position_string = f"{orb_dict['position'][0]:.4f},{orb_dict['position'][1]:.4f},{orb_dict['position'][2]:.4f}"
return f'Orbital @ {position_string}'

def _validate_keys(self, input_dict):
"""
Checks all the input_dict and tries to validate them, to ensure
Expand Down
7 changes: 7 additions & 0 deletions tests/tools/data/orbital/test_orbitals.py
Expand Up @@ -20,6 +20,13 @@
class TestOrbital(AiidaTestCase):
"""Test the Orbital base class"""

def test_orbital_str(self):
""""Test the output of __str__ method"""
orbital = Orbital(position=(1, 2, 3))
expected_output = 'Orbital @ 1.0000,2.0000,3.0000'

self.assertEqual(str(orbital), expected_output)

def test_required_fields(self):
"""Verify that required fields are validated."""
# position is required
Expand Down