Skip to content

Commit

Permalink
The cp command doesn't copy the installation state anymore.
Browse files Browse the repository at this point in the history
There is no need to create a new DevEnv class from an existing one, so
this intantiation option got removed.
  • Loading branch information
janosmurai committed Mar 7, 2024
1 parent 4d08f3f commit 4a3606b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 30 deletions.
1 change: 1 addition & 0 deletions dem/cli/command/cp_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def cp_given_dev_env(platform: Platform, dev_env_to_cp: DevEnv,
new_dev_env_name: str):
new_dev_env = copy.deepcopy(dev_env_to_cp)
new_dev_env.name = new_dev_env_name
new_dev_env.is_installed = False
platform.local_dev_envs.append(new_dev_env)
platform.flush_descriptors()

Expand Down
24 changes: 8 additions & 16 deletions dem/core/dev_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,26 @@ class DevEnv():
"CI/CD server",
)

def __init__(self, descriptor: dict | None = None,
dev_env_to_copy: "DevEnv | None" = None,
descriptor_path: str | None = None) -> None:
def __init__(self, descriptor: dict | None = None, descriptor_path: str | None = None) -> None:
""" Init the DevEnv class.
A new instance can be created:
- from a Dev Env descriptor
- based on another Dev Env
- from a descriptor avaialable at the given path.
Only one of the arguments can be used at a time.
Args:
descriptor -- the description of the Development Environment from the dev_env.json
file
dev_env_to_copy -- the DevEnv instance to copy
descriptor_path -- the path of the descriptor file
Exceptions:
ValueError -- if more than one of the arguments is not None
"""

# Only one of the arguments can be not None
if sum(arg is not None for arg in [descriptor, dev_env_to_copy, descriptor_path]) > 1:
if sum(arg is not None for arg in [descriptor, descriptor_path]) > 1:
raise ValueError("Only one of the arguments can be not None.")

if descriptor_path:
Expand All @@ -51,17 +47,13 @@ def __init__(self, descriptor: dict | None = None,
with open(descriptor_path, "r") as file:
descriptor = json.load(file)

if descriptor:
self.name: str = descriptor["name"]
self.tools: list[dict[str, str]] = descriptor["tools"]
descriptor_installed = descriptor.get("installed", "False")
if "True" == descriptor_installed:
self.is_installed = True
else:
self.is_installed = False
self.name: str = descriptor["name"]
self.tools: list[dict[str, str]] = descriptor["tools"]
descriptor_installed = descriptor.get("installed", "False")
if "True" == descriptor_installed:
self.is_installed = True
else:
self.name = dev_env_to_copy.name
self.tools = dev_env_to_copy.tools
self.is_installed = False

def check_image_availability(self, all_tool_images: ToolImages,
update_tool_image_store: bool = False,
Expand Down
7 changes: 5 additions & 2 deletions tests/cli/test_cp.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,20 @@ def test_check_new_dev_env_name_taken(mock_stderr_print):
def test_cp_given_dev_env():
# Test setup
mock_platform = MagicMock()
fake_dev_env_to_cp = MagicMock()
mock_dev_env_to_cp = MagicMock()
mock_dev_env_to_cp.name = "test_dev_env"
mock_dev_env_to_cp.is_installed = True

test_new_name = "test_cpd"

mock_platform.local_dev_envs = []

# Run unit under test
cp_cmd.cp_given_dev_env(mock_platform, fake_dev_env_to_cp, test_new_name)
cp_cmd.cp_given_dev_env(mock_platform, mock_dev_env_to_cp, test_new_name)

# Check expectations
assert mock_platform.local_dev_envs[0].name is test_new_name
assert mock_platform.local_dev_envs[0].is_installed is False

mock_platform.flush_descriptors.assert_called_once()

Expand Down
12 changes: 0 additions & 12 deletions tests/core/test_dev_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,6 @@ def test_DevEnv() -> None:
assert test_dev_env.name is test_descriptor["name"]
assert test_dev_env.tools is test_descriptor["tools"]

# Test setup
mock_base_dev_env = MagicMock()
mock_base_dev_env.name = "test_name"
mock_base_dev_env.tools = [MagicMock()]

# Run unit under test
test_dev_env = dev_env.DevEnv(dev_env_to_copy=mock_base_dev_env)

# Check expectations
assert test_dev_env.name is mock_base_dev_env.name
assert test_dev_env.tools is mock_base_dev_env.tools

@patch("dem.core.dev_env.json.load")
@patch("dem.core.dev_env.open")
@patch("dem.core.dev_env.os.path.exists")
Expand Down

0 comments on commit 4a3606b

Please sign in to comment.