Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide method which compares two ModuleStream objects #186

Closed
jankaluza opened this issue Feb 14, 2019 · 9 comments · Fixed by #265
Closed

Provide method which compares two ModuleStream objects #186

jankaluza opened this issue Feb 14, 2019 · 9 comments · Fixed by #265
Assignees
Labels
good first issue Easy tickets suitable for a new contributor

Comments

@jankaluza
Copy link
Contributor

In MBS unit-test, we want to be able to compare two modulemd objects to ensure they are the same. We currently have to do yaml.load(mmd1.dumps()) == yaml.load(mmd2.dumps()) to achieve that. It would be nice if there is some libmodulemd method to do the same.

@sgallagher sgallagher added the good first issue Easy tickets suitable for a new contributor label Feb 14, 2019
@sgallagher
Copy link
Collaborator

This should be a fairly easy (but not quick) addition to the 2.0 API. What we'll need:

Modulemd.ModuleStream (the parent class) will add a .equals() virtual function that will be implemented by Modulemd.ModuleStreamV1 and Modulemd.ModuleStreamV2. Its responsibility will be to recurse down into the various objects and variables making up the ModuleStream and perform an equality comparison on them. If any of them are different, it should return false.

As an implementation recommendation, the child objects should "chain up" to the parent class to compare the pieces common to all.

@sgallagher sgallagher changed the title Provide method which compares two modulemds Provide method which compares two ModuleStream objects Feb 14, 2019
@ayushi1998
Copy link

Hey I am an Outreachy applicant, would like to work on this issue!

@ghost
Copy link

ghost commented Feb 23, 2019

@sgallagher Virtual functions are not native to C, which is the language used for the source files in the v2 directory. Do you mind further explaining what you mean by "virtual function" and possibly point to some resources on how to implement them?

@sgallagher
Copy link
Collaborator

@indigoOmega021 The libmodulemd project is built atop the GObject toolkit. This offers us two advantages: the first is a rough approximation of object-orientation for the C language. The second is automatic introspection of these objects to create bindings for other languages such as python.

A pretty good tutorial on GObjects (including how to create virtual and pure-virtual functions) can be found at https://developer.gnome.org/gobject/stable/howto-gobject.html

In the case of libmodulemd, the parent class is located at https://github.com/fedora-modularity/libmodulemd/blob/master/modulemd/v2/modulemd-module-stream.c and the two existing child-classes are https://github.com/fedora-modularity/libmodulemd/blob/master/modulemd/v2/modulemd-module-stream-v1.c and https://github.com/fedora-modularity/libmodulemd/blob/master/modulemd/v2/modulemd-module-stream-v2.c

@ghost
Copy link

ghost commented Feb 26, 2019

@sgallagher I am trying to wrap my head around what "various objects and variables" to check in the equals function. Should I just use all of the getter methods for the Modulemd.ModuleStream, Modulemd.ModuleStreamV1, and Modulemd.ModuleStreamV2 classes and check that every word that is returned is equal for both objects? Any advice would be appreciated.

@sgallagher
Copy link
Collaborator

For those getters that return strings, yes. For getters that return other objects (integers, other GObject types, etc.), they need to have an appropriate comparison.

The comparison function needs to check every attribute that has a getter.

@sgallagher
Copy link
Collaborator

@indigoOmega021 OK, I should have broken this task up a lot more when I initially created it. I've now created issues #214 #215 #216 #217 and #218 to track the individual objects underneath this one that need their own comparisons.

I'd recommend picking one of those and working on that first and setting this one aside for now. Sorry for not realizing this sooner.

@OrionStar25
Copy link
Member

@sgallagher can I please work on this now?

@sgallagher
Copy link
Collaborator

Go ahead!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Easy tickets suitable for a new contributor
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants