Update cuds api according to m30#312
Conversation
The main parameter to add/get/remove items changed to `name`. Some `uid` specific methods added to carry out the same tasks with `uid`. Code simplified. `name` and `description` added to Simulation and CUDS classes. Perhaps I have to create multiple commits next time.
Current coverage is 72.40% (diff: 91.30%)@@ master #312 diff @@
==========================================
Files 115 115
Lines 6949 6969 +20
Methods 0 0
Messages 0 0
Branches 803 808 +5
==========================================
+ Hits 4970 5046 +76
+ Misses 1952 1880 -72
- Partials 27 43 +16
|
|
@tuopuu @kitchoi @SGGgarcia Please review this PR. |
| description=None): | ||
| self.name = name | ||
| self.description = description | ||
|
|
There was a problem hiding this comment.
Simulation does not have __slots__. User can always do:
sim = Simulation(cuds, engine_name)
sim.name = 'sim1'
sim.description = 'description for sim1'
Or, are the names/descriptions required in the API (then they should not be default to be None)?
There was a problem hiding this comment.
They are optional at the moment, exactly like the meta classes. Perhaps we have to turn CUDS and Simulation classes into CUDSItem derivaties, to have one universal data structure to deal with (it has been always the aim). However, for now I just decided to keep it simple.
There was a problem hiding this comment.
I agree with @mehdisadeghi here. For now it should be enough.
|
Looks like with this PR, it is then necessary to define a unique string |
| self.data = {} | ||
| self.dummpy_component1 = DummyComponent() | ||
| self.dummpy_component2 = DummyComponent() | ||
| self.dummpy_component1 = api.Box(name='mybox') |
There was a problem hiding this comment.
While at it, should fix this to self.dummy_component1 & 2. :)
There was a problem hiding this comment.
Oh gotcha! I'll fix them right away! :)
To some extent, yes.
AFAIK, Yes. Hence mentioning Adham to confirm. As I have commented in the code, the behavior of add/get/remove by name vs. by uid is ambiguous. What happens if a user adds a |
|
|
@tuopuu @kitchoi @SGGgarcia based on our discussions I made some changes. Please have a look. |
| return self._uid | ||
|
|
||
| @uid.setter | ||
| def uid(self, value): |
There was a problem hiding this comment.
If you don't provide the setter, it is read-only. Trying to set it would raise an AttributeError: can't set attribute
There was a problem hiding this comment.
I agree, please remove the setter and deleter readonly properties only need the property decorated function only
There was a problem hiding this comment.
Good to know that. I'll remove setters and deleters.
|
Is there a |
| if the component is not a CUDS component | ||
| ValueError | ||
| if the component is already added | ||
| if a component already exists |
There was a problem hiding this comment.
if a component with the same name already exists?
There was a problem hiding this comment.
Yes, corrected.
|
Please ignore the comment on the existence of test_get_nameless_component_by_name, i saw the test that i was looking for that is named differently. |
|
|
||
| self.assertEqual(c.get_by_uid(self.nameless_cuds_1.uid), | ||
| self.nameless_cuds_1) | ||
| self.assertIsNone(c.get(self.nameless_cuds_1.name)) |
There was a problem hiding this comment.
I guess my comment in CUDS.get is about whether it is a better user-experience to raise an Error here if name is None or empty.
|
Thanks @mehdisadeghi! Tests are diligent. There are a few minor issues above, except for that, the rest looks good to merge to me. |
| @property | ||
| def data(self): | ||
| """Data container for CUDS items.""" | ||
| return DataContainer(self._data) |
There was a problem hiding this comment.
What is the reasoning for creating a (shallow) copy of the self._data. If the purpose is to have a snapshot then this will work only if the contained keys and values are immutable. In any other case we have an object that references internal information that can change without anybody knowing about them.
If I am correct only the engine functions and returned dataset are required to support the snapshot principle. Does this extend to simulation? what is there a reason for this?
There was a problem hiding this comment.
You are correct, this will not work properly with our current mutable CUDS objects. I think the behavior of the data property regarding meta classes is unclear.
I think Simulation can have the same API as CUDS.
This PR simplifies CUDS class. Adds
nameanddescriptiontoCUDSandSimulationclasses. Moreover, usesnameas the main parameter to add/get/remove items inside CUDS.