From 95f7fa751d0475d4846a90acdfa5713191587a7a Mon Sep 17 00:00:00 2001 From: Sean Marquez Date: Wed, 8 Aug 2018 18:39:04 -0700 Subject: [PATCH 1/3] removed ?branch=dev --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 46959ff..f29256e 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ This project is intended to provide an object-oriented programming (OOP) paradigm for practicing Model-Based Systems Engineering (MBSE). [![Build Status](https://travis-ci.com/spacedecentral/SysML.py.svg?branch=dev)](https://travis-ci.com/spacedecentral/SysML.py) -[![Coverage Status](https://coveralls.io/repos/github/spacedecentral/SysML.py/badge.svg?branch=dev)](https://coveralls.io/github/spacedecentral/SysML.py?branch=dev) +[![Coverage Status](https://coveralls.io/repos/github/spacedecentral/SysML.py/badge.svg)](https://coveralls.io/github/spacedecentral/SysML.py?branch=dev) ## Package Contents From c22b44e7d982984efab6863e2dcb6e6744fcbf37 Mon Sep 17 00:00:00 2001 From: saiyaman Date: Thu, 9 Aug 2018 01:49:31 -0700 Subject: [PATCH 2/3] added tests for creating blocks with multiple stereotypes --- sysml/element.py | 6 ++---- tests/test_model.py | 26 ++++++++++++++++++-------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/sysml/element.py b/sysml/element.py index b7c8c10..78752b2 100644 --- a/sysml/element.py +++ b/sysml/element.py @@ -37,8 +37,6 @@ def _generateKey(name): """Takes a modeler-defined name and returns a formatted string for use as a key within the namespace of a parent model element""" if type(name) is str: return name[0].lower() + name[1:].replace(' ','') - else: - raise TypeError("'{}' is must be a string".format(str(name))) class Block(ModelElement): """This class defines a block @@ -77,10 +75,10 @@ def __init__(self, name=None, typeName=None, parts=None, references=None, values pass elif type(stereotype) is str and stereotype not in self._stereotype: self._stereotype.append(stereotype) - elif type(stereotype) is set: + elif type(stereotype) is list: for stereotype in stereotype: if type(stereotype) is str: - self._stereotype.add(stereotype) + self._stereotype.append(stereotype) else: raise TypeError("'{}' must be a string or set of strings".format(str(stereotype))) diff --git a/tests/test_model.py b/tests/test_model.py index 0cff340..7826a83 100644 --- a/tests/test_model.py +++ b/tests/test_model.py @@ -74,12 +74,10 @@ def test_block(model): model['Structure'].add() assert "add() missing 1 required positional argument: 'name'" in str(info.value) - model['Structure'].add(sysml.Block('Constitution-class Starship', stereotype='starship')) + model['Structure'].add(sysml.Block('Constitution-class Starship')) starship_block = model['Structure']['Constitution-class Starship'] - assert starship_block.stereotype == ['block', 'starship'] - - assert repr(model['Structure']['Constitution-class Starship']) == "\xabblock\xbb\n\xabstarship\xbb\nConstitution-class Starship" + assert repr(model['Structure']['Constitution-class Starship']) == "\xabblock\xbb\nConstitution-class Starship" assert repr(type(model['Structure']['Constitution-class Starship'])) == "" assert uuid.UUID(model['Structure']['Constitution-class Starship'].uuid, version=1) assert model['Structure']['Constitution-class Starship'].multiplicity == 1 @@ -91,22 +89,34 @@ def test_block(model): model['Structure']['Constitution-class Starship'].uuid = "47" assert "can't set attribute" in str(info.value) +def test_block_stereotype(): + """Test block stereotype""" + enterprise = sysml.Block('NCC-1701',stereotype='constitutionClass') + enterpriseD = sysml.Block('NCC-1701-D',stereotype=['galaxyClass','flagship']) + + assert enterprise.stereotype == ['block', 'constitutionClass'] + assert enterpriseD.stereotype == ['block', 'galaxyClass', 'flagship'] + + with pytest.raises(TypeError) as info: + enterpriseD = sysml.Block('NCC-1701-D',stereotype=47) + assert "must be a string or set of strings" in str(info.value) + # @pytest.mark.skip('WIP') def test_block_partProperty(model): """Add block elements as parts to parent blocks using add_part() method Parts added to a block element are dictionary-callable via the 'parts' attribute""" - with pytest.raises(TypeError) as info: - model['Structure']['Constitution-class Starship'].add_part() - assert "add_part() missing 1 required positional argument: 'name'" in str(info.value) - starship_block = model['Structure']['Constitution-class Starship'] starship_block.add_part(sysml.Block('Primary Hull')) starship_block.add_part(sysml.Block('Engineering Hull')) starship_block.add_part(sysml.Block('Cloaking device')) + with pytest.raises(TypeError) as info: + model['Structure']['Constitution-class Starship'].add_part() + assert "add_part() missing 1 required positional argument: 'name'" in str(info.value) + cloaking_device = starship_block.parts['Cloaking device'] assert repr(model['Structure']['Constitution-class Starship'].parts['Primary Hull']) == "\xabblock\xbb\nPrimary Hull" From 4554227ddf13110ff7e1929625f4d49a139a430a Mon Sep 17 00:00:00 2001 From: saiyaman Date: Thu, 9 Aug 2018 18:13:30 -0700 Subject: [PATCH 3/3] moved self._name constructor to abc, ModelElement() --- sysml/element.py | 63 ++++++++++++++---------------------------------- 1 file changed, 18 insertions(+), 45 deletions(-) diff --git a/sysml/element.py b/sysml/element.py index 78752b2..1ad8ace 100644 --- a/sysml/element.py +++ b/sysml/element.py @@ -16,10 +16,19 @@ class ModelElement(ABC): _id_no = 0 - def __init__(self): + def __init__(self, name=None): """UUID""" self._uuid = str(uuid.uuid1()) + """Name""" + if name is None: + self.__class__._id_no += 1 + self._name = self.__class__.__name__.lower() + str(self.__class__._id_no) + elif type(name) is str: + self._name = name + else: + raise TypeError("'{}' must be a string".format(str(name))) + def __repr__(self): return ''.join(["\xab" + _stereotype + "\xbb\n" for _stereotype in self._stereotype]) + "{}".format(self.name) @@ -67,7 +76,7 @@ def __init__(self, name=None, typeName=None, parts=None, references=None, values """Note: Block() class is intended for internal use by Model() class""" """Construct ModelElement""" - super().__init__() + super().__init__(name) """Stereotype""" self._stereotype = [self.__class__.__name__.lower()] @@ -82,15 +91,6 @@ def __init__(self, name=None, typeName=None, parts=None, references=None, values else: raise TypeError("'{}' must be a string or set of strings".format(str(stereotype))) - """Name""" - if name is None: - self.__class__._id_no += 1 - self._name = self.__class__.__name__.lower() + str(self.__class__._id_no) - elif type(name) is str: - self._name = name - else: - raise TypeError("'{}' must be a string".format(str(name))) - """Part Property""" self._parts = {} if parts is None: @@ -254,20 +254,11 @@ def __init__(self, name=None, txt=None, id=None): """Note: Requirement() class is intended for internal use by Model() class""" """Construct ModelElement""" - super().__init__() + super().__init__(name) """Stereotype""" self._stereotype = [self.__class__.__name__.lower()] - """Name""" - if name is None: - self.__class__._id_no += 1 - self._name = self.__class__.__name__.lower() + str(self.__class__._id_no) - elif type(name) is str: - self._name = name - else: - raise TypeError("'{}' must be a string".format(str(name))) - """Text""" if txt is None: self.txt = '' @@ -300,7 +291,7 @@ class ConstraintBlock(ModelElement): def __init__(self): """Construct ModelElement""" - super().__init__() + super().__init__(name) class Dependency(ModelElement): """This class defines a dependency""" @@ -330,7 +321,7 @@ def __init__(self, supplier, client, stereotype): raise Exception("'{}' is not a valid dependency".format(str(stereotype))) """Construct ModelElement""" - super().__init__() + super().__init__(self._name) @property def name(self): @@ -355,20 +346,11 @@ class Package(ModelElement): def __init__(self, name=None, elements=None): """Construct ModelElement""" - super().__init__() + super().__init__(name) """Stereotype""" self._stereotype = [self.__class__.__name__.lower()] - """Name""" - if name is None: - self.__class__._id_no += 1 - self._name = self.__class__.__name__.lower() + str(self.__class__._id_no) - elif type(name) is str: - self._name = name - else: - raise TypeError("'{}' must be a string".format(str(name))) - """Elements""" self._elements = {} if elements is None: @@ -429,7 +411,7 @@ class StateMachine(ModelElement): def __init__(self): """Construct ModelElement""" - super().__init__() + super().__init__(name) class Activity(ModelElement): """This class defines a activity""" @@ -437,7 +419,7 @@ class Activity(ModelElement): def __init__(self): """Construct ModelElement""" - super().__init__() + super().__init__(name) class Interaction(ModelElement): """This class defines an interaction""" @@ -445,20 +427,11 @@ class Interaction(ModelElement): def __init__(self, name=None, elements=None): """Construct ModelElement""" - super().__init__() + super().__init__(name) """Stereotype""" self._stereotype = self.__class__.__name__.lower() - """Name""" - if name is None: - self.__class__._id_no += 1 - self._name = self.__class__.__name__ + str(self.__class__._id_no) - elif type(name) is str: - self._name = name - else: - raise TypeError("'{}' must be a string".format(str(name))) - """Elements""" if elements is None: elements = {}