nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: remind101/stacker
Pull request #119 (2015-11-24 19:40:00)

Move get_fqn to a method, add tests


Patch:
diff --git a/stacker/context.py b/stacker/context.py
index 5cc4f35..1897027 100644
--- a/stacker/context.py
+++ b/stacker/context.py
@@ -3,6 +3,19 @@ from .config import parse_config
 from .stack import Stack
 
 
+def get_fqn(base_fqn, name=None):
+    """Return the fully qualified name of an object within this context.
+
+    If the name passed already appears to be a fully qualified name, it
+    will be returned with no further processing.
+
+    """
+    if name and name.startswith(base_fqn + '-'):
+        return name
+
+    return '-'.join(filter(None, [base_fqn, name]))
+
+
 class Context(object):
     """The context under which the current stacks are being executed.
 
@@ -88,7 +101,4 @@ class Context(object):
         will be returned with no further processing.
 
         """
-        if name and name.startswith(self._base_fqn + '-'):
-            return name
-
-        return '-'.join(filter(None, [self._base_fqn, name]))
+        return get_fqn(self._base_fqn, name)


Test patch:
diff --git a/stacker/tests/test_context.py b/stacker/tests/test_context.py
index 669e59b..92a81b7 100644
--- a/stacker/tests/test_context.py
+++ b/stacker/tests/test_context.py
@@ -1,6 +1,6 @@
 import unittest
 
-from ..context import Context
+from ..context import Context, get_fqn
 from ..exceptions import MissingEnvironment
 
 
@@ -64,3 +64,20 @@ class TestContext(unittest.TestCase):
         context = Context(self.environment)
         fqn = context.get_fqn('stack1')
         self.assertEqual(fqn, 'namespace-stack1')
+
+
+class TestFunctions(unittest.TestCase):
+    """ Test the module level functions """
+    def test_get_fqn_redundant_base(self):
+        base = "woot"
+        name = "woot-blah"
+        self.assertEqual(get_fqn(base, name), name)
+
+    def test_get_fqn_only_base(self):
+        base = "woot"
+        self.assertEqual(get_fqn(base), base)
+
+    def test_get_fqn_full(self):
+        base = "woot"
+        name = "blah"
+        self.assertEqual(get_fqn(base, name), "%s-%s" % (base, name))