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

Fix for #498. Proferences throw error when tabs yml file is empty #506

Merged
merged 2 commits into from
Dec 13, 2023
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
6 changes: 4 additions & 2 deletions speedwagon/config/tabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def data(self) -> List[CustomTabData]:
"""Get the data for custom tabs."""

@abc.abstractmethod
def save(self, tabs: List[CustomTabData]):
def save(self, tabs: List[CustomTabData]) -> None:
"""Get the data for custom tabs."""


Expand Down Expand Up @@ -55,6 +55,8 @@ def read_file(yaml_file: str) -> str:

def decode_tab_settings_yml_data(self, data: str) -> Dict[str, List[str]]:
"""Decode tab settings yml data."""
if len(data) == 0:
return {}
tabs_config_data = yaml.load(data, Loader=yaml.SafeLoader)
if not isinstance(tabs_config_data, dict):
raise speedwagon.exceptions.FileFormatError("Failed to parse file")
Expand Down Expand Up @@ -105,7 +107,7 @@ def data(self) -> List[CustomTabData]:
for tab_name, workflow_names in yml_data.items()
]

def save(self, tabs: List[CustomTabData]):
def save(self, tabs: List[CustomTabData]) -> None:
"""Write tabs to a yaml file."""
self.file_writer_strategy.save(self.yaml_file, tabs)

Expand Down
9 changes: 7 additions & 2 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def data_reader():

def test_yaml_errors_throws_tab_load_failure(self, monkeypatch):
def data_reader():
return ""
return "garblygoock"

config_loader = \
speedwagon.config.tabs.CustomTabsYamlConfig(yaml_file="myfaketabs.yml")
Expand All @@ -39,7 +39,7 @@ def data_reader():

def test_file_format_error_throws_tab_load_failure(self, monkeypatch):
def data_reader():
return ""
return "garblygoock"

config_loader = \
speedwagon.config.tabs.CustomTabsYamlConfig(yaml_file="myfaketabs.yml")
Expand Down Expand Up @@ -95,6 +95,11 @@ def test_save(self):
config_loader.save([])
assert config_loader.file_writer_strategy.save.called is True

def test_load_empty_file(self):
config_loader = \
speedwagon.config.tabs.CustomTabsYamlConfig(yaml_file="tabs.yml")
config_loader.file_reader_strategy.read_file = Mock(return_value="")
assert config_loader.data() == []

class TestTabsWriteStrategy:
def test_write_data_is_called(self, monkeypatch):
Expand Down
11 changes: 8 additions & 3 deletions tests/test_startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ def test_missing_workflow(monkeypatch, capsys):
load.__class__ = dict
monkeypatch.setattr(yaml, "load", load)
def read_file(*args, **kwargs):
return ""
return """
current:
- Medusa Preingest Curation
"""
monkeypatch.setattr(
speedwagon.config.tabs.TabsYamlFileReader,
"read_file",
Expand Down Expand Up @@ -116,10 +119,12 @@ def test_get_custom_tabs_loads_workflows_from_file(monkeypatch):
]
}
load = Mock(name="load", return_value=tabs_config_data)
load.__class__ = dict
monkeypatch.setattr(yaml, "load", load)
def read_file(*args, **kwargs):
return ""
return """
my workflow:
- spam
"""
monkeypatch.setattr(
speedwagon.config.tabs.TabsYamlFileReader,
"read_file",
Expand Down