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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: fix __repr__ of Config #1403

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions qcodes/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,12 +355,13 @@ def save_to_cwd(self):
self.save_config(self.cwd_file_name)
self.save_schema(self.schema_cwd_file_name)

def describe(self, name):
def describe(self, name: str) -> str:
"""
Describe a configuration entry

Args:
name (str): name of entry to describe
name: name of entry to describe in 'dotdict' notation,
e.g. name="user.scriptfolder"
"""
val = self.current_config
sch = self.current_schema["properties"]
Expand Down Expand Up @@ -392,9 +393,9 @@ def __getattr__(self, name):

def __repr__(self):
old = super().__repr__()
output = f"""Current values: \n {current_config} \n
Current paths: \n {self._loaded_config_files} \n
{old}"""
output = (f"Current values: \n {self.current_config} \n"
f"Current paths: \n {self._loaded_config_files} \n"
f"{old}")
return output


Expand Down
35 changes: 35 additions & 0 deletions qcodes/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,3 +325,38 @@ def test_update_from_path(path_to_config_file_on_disk):
expected_path = os.path.join(path_to_config_file_on_disk,
'qcodesrc.json')
assert cfg.current_config_path == expected_path


def test_repr():
cfg = Config()
rep = cfg.__repr__()

expected_rep = (f"Current values: \n {cfg.current_config} \n"
f"Current paths: \n {cfg._loaded_config_files} \n"
f"{super(Config, cfg).__repr__()}")

assert rep == expected_rep


def test_add_and_describe():
"""
Test that a key an be added and described
"""
with default_config():

key = 'newkey'
value ='testvalue'
value_type ='string'
description ='A test'
default = 'testdefault'

cfg = Config()
cfg.add(key=key, value=value, value_type=value_type,
description=description, default=default)


desc = cfg.describe(f'user.{key}')
expected_desc = (f"{description}.\nCurrent value: {value}. "
f"Type: {value_type}. Default: {default}.")

assert desc == expected_desc