Skip to content

Commit

Permalink
refactor: BaseCloud method returns config instead of setting config
Browse files Browse the repository at this point in the history
This commit renames the _check_and_set_config method of the BaseCloud
class to _check_and_get_config, and modifies the method such that it
returns a dict instead of setting the config instance variable. This
change facilitates modification of the method's behaviour during unit
testing.
  • Loading branch information
danpdraper committed Nov 28, 2024
1 parent e80c896 commit 552acb0
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions pycloudlib/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import os
import re
from abc import ABC, abstractmethod
from typing import Any, List, Optional, Sequence
from typing import Any, List, MutableMapping, Optional, Sequence

import paramiko

Expand Down Expand Up @@ -61,7 +61,7 @@ def __init__(
self.created_images: List[str] = []

self._log = logging.getLogger("{}.{}".format(__name__, self.__class__.__name__))
self._check_and_set_config(config_file, required_values)
self.config = self._check_and_get_config(config_file, required_values)

self.tag = get_timestamped_tag(tag) if timestamp_suffix else tag
self._validate_tag(self.tag)
Expand Down Expand Up @@ -261,11 +261,11 @@ def use_key(self, public_key_path, private_key_path=None, name=None):
name=name,
)

def _check_and_set_config(
def _check_and_get_config(
self,
config_file: Optional[ConfigFile],
required_values: _RequiredValues,
):
) -> MutableMapping[str, Any]:
"""Set pycloudlib configuration.
Checks if values required to launch a cloud instance are present.
Expand All @@ -282,9 +282,8 @@ def _check_and_set_config(
# of them were provided, config file is loaded and the values that
# were passed in work as overrides
if required_values and all(v is not None for v in required_values):
self.config = {}
else:
self.config = parse_config(config_file)[self._type]
return {}
return parse_config(config_file)[self._type]

@staticmethod
def _validate_tag(tag: str):
Expand Down

0 comments on commit 552acb0

Please sign in to comment.