Skip to content

Commit f5eeeac

Browse files
committed
Add unit test
1 parent 2e07e5e commit f5eeeac

File tree

1 file changed

+61
-1
lines changed

1 file changed

+61
-1
lines changed

tests/unit/sagemaker/workflow/test_notebook_job_step.py

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313
from __future__ import absolute_import
1414

1515
import unittest
16+
1617
from mock import Mock, patch
1718

18-
from sagemaker.workflow.notebook_job_step import NotebookJobStep
1919
from sagemaker.workflow.functions import Join
20+
from sagemaker.workflow.notebook_job_step import NotebookJobStep
2021

2122
REGION = "us-west-2"
2223
PIPELINE_NAME = "test-pipeline-name"
@@ -573,3 +574,62 @@ def _create_step_with_required_fields(self):
573574
image_uri=IMAGE_URI,
574575
kernel_name=KERNEL_NAME,
575576
)
577+
578+
def test_environment_variables_not_shared(self):
579+
"""Test that environment variables are not shared between NotebookJob steps"""
580+
# Setup shared environment variables
581+
shared_env_vars = {"test": "test"}
582+
583+
# Create two steps with the same environment variables dictionary
584+
step1 = NotebookJobStep(
585+
name="step1",
586+
input_notebook=INPUT_NOTEBOOK,
587+
image_uri=IMAGE_URI,
588+
kernel_name=KERNEL_NAME,
589+
environment_variables=shared_env_vars,
590+
)
591+
592+
step2 = NotebookJobStep(
593+
name="step2",
594+
input_notebook=INPUT_NOTEBOOK,
595+
image_uri=IMAGE_URI,
596+
kernel_name=KERNEL_NAME,
597+
environment_variables=shared_env_vars,
598+
)
599+
600+
# Get the arguments for both steps
601+
step1_args = step1.arguments
602+
step2_args = step2.arguments
603+
604+
# Verify that the environment variables are different objects
605+
self.assertIsNot(
606+
step1_args["Environment"],
607+
step2_args["Environment"],
608+
"Environment dictionaries should be different objects",
609+
)
610+
611+
# Verify that modifying one step's environment doesn't affect the other
612+
step1_env = step1_args["Environment"]
613+
step2_env = step2_args["Environment"]
614+
615+
# Both should have the original test value
616+
self.assertEqual(step1_env["test"], "test")
617+
self.assertEqual(step2_env["test"], "test")
618+
619+
# Modify step1's environment
620+
step1_env["test"] = "modified"
621+
622+
# Verify step2's environment remains unchanged
623+
self.assertEqual(step2_env["test"], "test")
624+
625+
# Verify notebook names are correct for each step
626+
self.assertEqual(
627+
step1_env["SM_INPUT_NOTEBOOK_NAME"],
628+
os.path.basename(INPUT_NOTEBOOK),
629+
"Step 1 should have its own notebook name",
630+
)
631+
self.assertEqual(
632+
step2_env["SM_INPUT_NOTEBOOK_NAME"],
633+
os.path.basename(INPUT_NOTEBOOK),
634+
"Step 2 should have its own notebook name",
635+
)

0 commit comments

Comments
 (0)