diff --git a/VERSION.txt b/VERSION.txt index 01008f1..5030bbb 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -6.4.0-d \ No newline at end of file +6.4.2-d \ No newline at end of file diff --git a/scripttease/library/commands/base.py b/scripttease/library/commands/base.py index fc78220..9155d51 100644 --- a/scripttease/library/commands/base.py +++ b/scripttease/library/commands/base.py @@ -138,6 +138,28 @@ class Command(object): return "\n".join(b) + def has_attribute(self, name): + """Indicates whether the command has the named, dynamic attribute. + + :param name: The name of the attribute to be checked. + :type name: str + + :rtype: bool + + """ + return name in self._attributes + + def set_attribute(self, name, value): + """Set the value of a dynamic attribute. + + :param name: The name of the attribute. + :type name: str + + :param value: The value of the attribute. + + """ + self._attributes[name] = value + def _get_statement(self): """By default, get the statement passed upon command initialization. @@ -222,6 +244,31 @@ class ItemizedCommand(object): return "\n".join(a) + def has_attribute(self, name): + """Indicates whether the command has the named, dynamic attribute. + + :param name: The name of the attribute to be checked. + :type name: str + + :rtype: bool + + """ + return name in self.kwargs + + def set_attribute(self, name, value): + """Set the value of a dynamic attribute. + + :param name: The name of the attribute. + :type name: str + + :param value: The value of the attribute. + + .. note:: + This is applied to all command in the itemized list. + + """ + self.kwargs[name] = value + class Sudo(object): """Helper class for defining sudo options.""" diff --git a/tests/test_library_commands_base.py b/tests/test_library_commands_base.py index 115a73c..f6bafb6 100644 --- a/tests/test_library_commands_base.py +++ b/tests/test_library_commands_base.py @@ -35,6 +35,10 @@ class TestCommand(object): statement = c.get_statement() assert "if [[ $?" in statement + def test_has_attribute(self): + c = Command("ls -ls") + assert c.has_attribute("testing") is False + def test_init(self): c = Command("ls -ls", sudo=Sudo(user="deploy")) assert isinstance(c.sudo, Sudo) @@ -60,6 +64,12 @@ class TestCommand(object): c = Command("ls -ls") assert repr(c) == "" + def test_set_attribute(self): + c = Command("ls -ls") + assert c.testing is None + c.set_attribute("testing", True) + assert c.testing is True + class TestItemizedCommand(object): @@ -80,6 +90,16 @@ class TestItemizedCommand(object): assert "psycopg2-binary" in statement assert "django" in statement + def test_has_attribute(self): + c = ItemizedCommand(python_pip, ["Pillow", "psycopg2-binary", "django"], "$item") + assert c.has_attribute("testing") is False + def test_repr(self): c = ItemizedCommand(python_pip, ["Pillow", "psycopg2-binary", "django"], "$item") assert repr(c) == "" + + def test_set_attribute(self): + c = ItemizedCommand(python_pip, ["Pillow", "psycopg2-binary", "django"], "$item") + assert c.testing is None + c.set_attribute("testing", True) + assert c.testing is True