1# Copyright (c) 2011, Willow Garage, Inc.
2# All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions are met:
6#
7#     * Redistributions of source code must retain the above copyright
8#       notice, this list of conditions and the following disclaimer.
9#     * Redistributions in binary form must reproduce the above copyright
10#       notice, this list of conditions and the following disclaimer in the
11#       documentation and/or other materials provided with the distribution.
12#     * Neither the name of the Willow Garage, Inc. nor the names of its
13#       contributors may be used to endorse or promote products derived from
14#       this software without specific prior written permission.
15#
16# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26# POSSIBILITY OF SUCH DAMAGE.
27
28
29def test_RosdepDatabaseEntry():
30    # not muich to test with container
31    from rosdep2.model import RosdepDatabaseEntry
32    d = RosdepDatabaseEntry({'a': 1}, [], 'foo')
33    assert d.rosdep_data == {'a': 1}
34    assert d.view_dependencies == []
35    assert d.origin == 'foo'
36
37
38def test_RosdepDatabase():
39    from rosdep2.model import RosdepDatabase
40
41    db = RosdepDatabase()
42    assert not db.is_loaded('foo')
43
44    data = {'a': 1}
45    db.set_view_data('foo', data, [], 'origin1')
46    assert db.is_loaded('foo')
47    entry = db.get_view_data('foo')
48    assert entry.rosdep_data == data
49    assert entry.origin == 'origin1'
50    assert entry.view_dependencies == []
51    # make sure data is copy
52    data['a'] = 2
53    assert entry.rosdep_data != data
54
55    data = {'b': 2}
56    db.set_view_data('bar', data, ['foo'], 'origin2')
57    assert db.is_loaded('bar')
58    entry = db.get_view_data('bar')
59    assert entry.rosdep_data == data
60    assert entry.origin == 'origin2'
61    assert entry.view_dependencies == ['foo']
62
63    # override entry for bar
64    data = {'b': 3}
65    assert db.is_loaded('bar')
66    db.set_view_data('bar', data, ['baz', 'blah'], 'origin3')
67    assert db.is_loaded('bar')
68    entry = db.get_view_data('bar')
69    assert entry.rosdep_data == data
70    assert entry.origin == 'origin3'
71    assert set(entry.view_dependencies) == set(['baz', 'blah'])
72
73
74def test_RosdepDatabase_get_view_dependencies():
75    from rosdep2.model import RosdepDatabase
76
77    data = {'a': 1}
78    db = RosdepDatabase()
79
80    db.set_view_data('foo', data, [], 'origin')
81    assert [] == db.get_view_dependencies('foo')
82
83    db.set_view_data('bar', data, ['foo'], 'origin')
84    assert ['foo'] == db.get_view_dependencies('bar')
85
86    db.set_view_data('baz', data, ['bar'], 'origin')
87    assert ['foo', 'bar'] == db.get_view_dependencies('baz')
88
89    db.set_view_data('rad', data, [], 'origin')
90    db.set_view_data('fad', data, ['baz', 'rad'], 'origin')
91    retval = db.get_view_dependencies('fad')
92    assert set(['baz', 'rad', 'foo', 'bar']) == set(retval), retval
93    assert len(retval) == 4
94