[PATCH 2 of 2 compound] Backport utility functions from the saem_ref cube

Denis Laxalde denis.laxalde at logilab.fr
Wed Mar 8 11:07:58 CET 2017


Sylvain Thenault a écrit :
> # HG changeset patch
> # User Sylvain Thénault <sylvain.thenault at logilab.fr>
> # Date 1488957508 -3600
> #      Wed Mar 08 08:18:28 2017 +0100
> # Node ID 8f10df9fd179c2c0d7e2552635a9f202c6448d21
> # Parent  ed8dc2bddcbe5235f84f2831f5e9acc752cf659f
> Backport utility functions from the saem_ref cube
>
> and write some testsabout graph traversal functions.
>
> diff --git a/cubicweb_compound/lib.py b/cubicweb_compound/lib.py
> new file mode 100644
> --- /dev/null
> +++ b/cubicweb_compound/lib.py

utils.py?


> diff --git a/test/test_lib.py b/test/test_lib.py
> new file mode 100644
> --- /dev/null
> +++ b/test/test_lib.py
> @@ -0,0 +1,74 @@
> +# copyright 2017 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
> +# contact http://www.logilab.fr -- mailto:contact at logilab.fr
> +#
> +# This program is free software: you can redistribute it and/or modify it under
> +# the terms of the GNU Lesser General Public License as published by the Free
> +# Software Foundation, either version 2.1 of the License, or (at your option)
> +# any later version.
> +#
> +# This program is distributed in the hope that it will be useful, but WITHOUT
> +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
> +# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
> +# details.
> +#
> +# You should have received a copy of the GNU Lesser General Public License along
> +# with this program. If not, see <http://www.gnu.org/licenses/>.
> +"""cubicweb-compound tests"""
> +
> +from cubicweb.devtools.testlib import CubicWebTC
> +
> +from cubicweb_compound import CompositeGraph
> +from cubicweb_compound import lib
> +
> +
> +class LibFunctionTC(CubicWebTC):
> +
> +    def test_graph_relations(self):
> +        graph = CompositeGraph(self.schema)
> +        structure = graph.parent_structure('Agent')
> +        structurals, optionals, mandatories = lib.graph_relations(self.schema, structure)
> +        self.assertEqual(structurals,
> +                         set([
> +                             ('event', 'object'),
> +                             ('biography', 'object'),
> +                             ('relates', 'object'),
> +                             ('account', 'object'),
> +                             ('narrated_by', 'subject'),
> +                             ('comments', 'subject'),
> +                         ]))

in all these tests, it'd help if you could define an "expected" variable 
instead of defining this in assertEqual calls.

> +        self.assertEqual(optionals,
> +                         set([
> +                             ('narrated_by', 'subject'),
> +                             ('relates', 'object'),
> +                         ]))
> +        self.assertEqual(mandatories, set())
> +
> +    def test_optional_relations(self):
> +        graph = CompositeGraph(self.schema)
> +        structure = graph.parent_structure('Agent')
> +        optional = lib.optional_relations(self.schema, structure)
> +        self.assertEqual(optional,
> +                         {
> +                             'Anecdote': set([('narrated_by', 'subject')]),
> +                             'Event': set([('relates', 'object')]),
> +                         })
> +
> +    def test_mandatory_rdefs(self):
> +        graph = CompositeGraph(self.schema)
> +        structure = graph.parent_structure('Agent')
> +        mandatory = [(str(rdef), role) for rdef, role in lib.mandatory_rdefs(self.schema,
> +                                                                             structure)]
> +        self.assertEqual(mandatory,
> +                         [
> +                             ('relation Comment comments Anecdote', 'object'),
> +                             ('relation Comment comments Comment', 'object'),
> +                             ('relation Agent account OnlineAccount', 'subject'),
> +                             ('relation Biography event Anecdote', 'subject'),
> +                             ('relation Agent biography Biography', 'subject'),
> +                             ('relation Biography event Event', 'subject'),
> +                         ])
> +
> +
> +if __name__ == '__main__':
> +    import unittest
> +    unittest.main()
>



More information about the saem-devel mailing list