Пример #1
0
    def test_load_and_write_cond(self):
        """compdesc.load returns a component with packages"""
        os.system('''
cat >a.xml <<EOF
<?xml version="1.0" encoding="utf-8"?>
<component>
  <contents>
    <deb>
      <cond><![CDATA[ apache (>>2) ]]></cond>
      <deb ref="sha-1:aaa">
        <cond>apache</cond>
      </deb>
    </deb>
  </contents>
</component>
EOF
cp a.xml b.xml
''')
        desc = ComponentDescriptor('a.xml')
        desc.write()
        self.assert_equals_long(open('b.xml').read(), open('a.xml').read())
        condition = desc.contents[0].reference.condition

        a = MockPackage('apache', '2-1', deb, 'sha-1:aaa')
        b = MockPackage('apache', '1.3', deb, 'sha-1:bbb')

        assert condition.evaluate(a)
        assert not condition.evaluate(b)
Пример #2
0
 def test_get_file(self):
     p = MockPackage('a', DebianVersion('2.3-1'), deb, arch='i386')
     self.assert_equal('a_2.3-1_i386.deb', deb.get_filename(p))
     self.assert_equal('a_2.3-1.dsc', dsc.get_filename(p))
     p = MockPackage('a', DebianVersion('1:2.3'), deb, arch='i386')
     self.assert_equal('a_2.3_i386.deb', deb.get_filename(p))
     self.assert_equal('a_2.3.dsc', dsc.get_filename(p))
Пример #3
0
 def test_diff_downgrade(self):
     a1 = MockPackage('a', '1', deb, arch = 'i386')
     a2 = MockPackage('a', '2', deb, arch = 'i386')
     list1 = [ a2 ]
     list2 = [ a1 ]
     diffs = iter_diffs(list1, list2)
     expected = Set([ ('downgrade', a2, a1) ])
     self.assert_equals_long(expected, Set(diffs))
Пример #4
0
 def test_diff_remove(self):
     a = MockPackage('a', '1', deb, arch = 'i386')
     b = MockPackage('b', '1', deb, arch = 'i386')
     list1 = [ a, b]
     list2 = []
     diffs = iter_diffs(list1, list2)
     expected = Set([ ('drop', a, None),
                      ('drop', b, None) ])
     self.assert_equals_long(expected, Set(diffs))
Пример #5
0
 def test_diff_same(self):
     a = MockPackage('a', '1', deb, arch = 'i386')
     b = MockPackage('b', '1', deb, arch = 'i386')
     list1 = [ a, b ]
     list2 = list1[:]
     list2.reverse()
     diffs = iter_diffs(list1, list2)
     expected = Set([ ('unchanged', a, a),
                      ('unchanged', b, b) ])
     self.assert_equals_long(expected, Set(diffs))
Пример #6
0
    def test_conditional_include(self):
        os.system('''
cat >b.xml <<EOF
<?xml version="1.0" encoding="utf-8"?>
<component>
  <contents>
    <deb ref="sha-1:aaa">
      <name>apache</name>
    </deb>
    <deb ref="sha-1:bbb">
      <name>libc6</name>
    </deb>
    <deb ref="sha-1:ccc">
      <name>ls</name>
    </deb>
  </contents>
</component>
EOF
''')
        os.system('''
cat >a.xml <<EOF
<?xml version="1.0" encoding="utf-8"?>
<component>
  <contents>
    <component>
      <file>b.xml</file>
      <limit>apache</limit>
      <exclude>ls</exclude>
    </component>
  </contents>
</component>
EOF
cp a.xml c.xml
''')
        apache = MockPackage('apache', '1', deb, 'sha-1:aaa', arch='i386')
        libc = MockPackage('libc6', '1', deb, 'sha-1:bbb', arch='i386')
        ls = MockPackage('ls', '1', deb, 'sha-1:ccc', arch='i386')
        cache = ShamCache()
        cache.add(apache)
        cache.add(libc)
        cache.add(ls)

        desc_a = ComponentDescriptor('a.xml')
        desc_a.write()
        self.assert_equals_long(open('c.xml').read(), open('a.xml').read())
        component_a = desc_a.load(cache)
        assert isinstance(component_a, Component)
        expected = [apache]
        actual = list(component_a.iter_packages())
        self.assert_equal(expected, actual)
Пример #7
0
    def test_load_and_use_star_cond(self):
        """compdesc.load returns a component with packages"""
        os.system('''
cat >a.xml <<EOF
<?xml version="1.0" encoding="utf-8"?>
<component>
  <contents>
    <dsc>
      <name>apache</name>
      <dsc ref="sha-1:ccc">
        <name>apache</name>
      </dsc>
      <deb ref="sha-1:aaa">
        <name>apache</name>
      </deb>
      <deb ref="sha-1:bbb">
        <name>apache-common</name>
      </deb>
    </dsc>
    <dsc>
      <cond><![CDATA[ * apache (>=2) ]]></cond>
    </dsc>
    <src>
      <cond><![CDATA[ * apache (>=2) ]]></cond>
    </src>
    <bin>
      <cond><![CDATA[ * apache-common (>=2) ]]></cond>
    </bin>
  </contents>
</component>
EOF
cp a.xml b.xml
''')
        desc = ComponentDescriptor('a.xml')
        desc.write()
        self.assert_equals_long(open('b.xml').read(), open('a.xml').read())
        condition = desc.contents[1].rule.condition

        a = MockPackage('apache', '2', deb, 'sha-1:aaa')
        b = MockPackage('apache-commmon', '2', deb, 'sha-1:bbb')
        c = MockPackage('apache', '2', dsc, 'sha-1:ccc')
        a.complement = [c]
        b.complement = [c]
        c.complement = [a, b]

        assert condition.evaluate(a)
        assert condition.evaluate(b)
        assert not condition.evaluate(c)

        src_condition = desc.contents[2].rule.condition
        assert src_condition.evaluate(a)
        assert src_condition.evaluate(b)
        assert not src_condition.evaluate(c)
Пример #8
0
    def test_load_sub_component_meta(self):
        """Be sure metadata gets loaded from subcomponents even if
        the toplevel component has none.
        """
        open('test1.xml', 'w').write('''<?xml version="1.0"?>
<component>
  <contents>
    <component>test2.xml</component>
  </contents>
</component>
''')
        open('test2.xml', 'w').write('''<?xml version="1.0"?>
<component>
  <contents>
    <deb ref="sha-1:aaa">
      <meta>
        <necessity>mandatory</necessity>
      </meta>
    </deb>
  </contents>
</component>
''')
        cache = ShamCache()
        package = MockPackage('a', '1', deb, 'sha-1:aaa')
        cache.add(package)
        desc = ComponentDescriptor('test1.xml')
        comp = desc.load(cache)
        assert package in list(comp.iter_packages())
        self.assert_equal("mandatory", package[('pdk', 'necessity')])
Пример #9
0
    def test_get_child_condition_fn(self):
        apache_deb = MockPackage('apache', '1', deb, 'sha-1:aaa')
        apache_udeb = MockPackage('apache', '1', udeb, 'sha-1:aaa')
        apache_rpm = MockPackage('apache', '1', rpm, 'sha-1:aaa')
        apache_dsc = MockPackage('apache', '1', dsc, 'sha-1:aaa')
        apache_srpm = MockPackage('apache', '1', srpm, 'sha-1:aaa')

        self.assert_equals(get_deb_child_condition,
                           get_child_condition_fn(apache_deb))
        self.assert_equals(get_deb_child_condition,
                           get_child_condition_fn(apache_udeb))
        self.assert_equals(get_dsc_child_condition,
                           get_child_condition_fn(apache_dsc))
        self.assert_equals(get_rpm_child_condition,
                           get_child_condition_fn(apache_rpm))
        self.assert_equals(get_srpm_child_condition,
                           get_child_condition_fn(apache_srpm))
Пример #10
0
    def test_get_srpm_child_condition(self):
        version = RPMVersion(version_string='1-2')
        apache_srpm = MockPackage('apache', version, srpm, 'sha-1:aaa')
        expected = rules.ac([
            rules.rc(eq, 'pdk', 'source-rpm', 'apache-1-2.src.rpm'),
            rules.rc(eq, 'pdk', 'type', 'rpm')
        ])

        self.assert_equals(expected, get_srpm_child_condition(apache_srpm))
Пример #11
0
 def test_diff_with_distractions(self):
     a = MockPackage('a', '1', deb, arch = 'i386')
     b = MockPackage('b', '1', deb, arch = 'i386')
     a_arm = MockPackage('a', '1', deb, arch = 'arm')
     c = MockPackage('c', '1', deb, arch = 'i386')
     list1 = [ a, b ]
     list2 = list1[:]
     list2.reverse()
     list2.append(c)
     list1.append(a_arm)
     diffs = iter_diffs(list1, list2)
     expected = Set([ ('unchanged', a, a),
                      ('unchanged', b, b),
                      ('add', c, None),
                      ('drop', a_arm, None) ])
     diffs = list(diffs)
     diffs.sort()
     expected = list(expected)
     expected.sort()
     self.assert_equals_long(expected, diffs)
Пример #12
0
    def test_complement(self):
        """compdesc.load returns a component with packages"""
        os.system('''
cat >a.xml <<EOF
<?xml version="1.0" encoding="utf-8"?>
<component>
  <contents>
    <deb>
      <deb ref="sha-1:aaa"/>
      <deb ref="sha-1:bbb"/>
      <dsc ref="sha-1:ccc"/>
    </deb>
    <dsc>
      <dsc ref="sha-1:ccc"/>
      <deb ref="sha-1:aaa"/>
      <deb ref="sha-1:bbb"/>
      <deb ref="sha-1:ddd"/>
    </dsc>
  </contents>
</component>
EOF
''')
        desc = ComponentDescriptor('a.xml')
        cache = ShamCache(make_copies=True)
        a = MockPackage('a', '1', deb, 'sha-1:aaa', arch='i386')
        b = MockPackage('b', '1', deb, 'sha-1:bbb', arch='i386')
        c = MockPackage('c', '1', dsc, 'sha-1:ccc', arch='any')
        d = MockPackage('b', '1', deb, 'sha-1:ddd', arch='i386')
        cache.add(a)
        cache.add(b)
        cache.add(c)
        cache.add(d)
        component = desc.load(cache)
        packages = list(component.iter_packages())
        self.assert_equal([c], packages[0].complement)
        self.assert_equal([c], packages[1].complement)
        self.assert_equal([a, b], packages[2].complement)
        self.assert_equal([a, b, d], packages[3].complement)
        self.assert_equal([c], packages[4].complement)
        self.assert_equal([c], packages[5].complement)
        self.assert_equal([c], packages[6].complement)
Пример #13
0
    def test_get_deb_child_condition(self):
        sp_version = DebianVersion('1-2')
        extra = {('pdk', 'sp-name'): 'one', ('pdk', 'sp-version'): sp_version}
        apache_deb = MockPackage('apache', '1', deb, 'sha-1:aaa', extra)

        expected = rules.ac([
            rules.rc(eq, 'pdk', 'name', 'one'),
            rules.rc(eq, 'pdk', 'version', '1-2'),
            rules.rc(eq, 'pdk', 'type', 'dsc')
        ])

        self.assert_equals(expected, get_deb_child_condition(apache_deb))
Пример #14
0
    def test_get_file(self):
        class MockType(object):
            format_string = 'deb'
            type_string = 'dsc'

            def get_filename(self, dummy):
                return 'asdfjkl'

        package_type = MockType()
        p = MockPackage('a', '2.3-1.1', package_type, arch='i386')
        self.assert_equal('asdfjkl', p.filename)
        p[('pdk', 'filename')] = 'superduper'
        self.assert_equal('superduper', p.filename)
Пример #15
0
    def test_get_dsc_child_condition(self):
        version = DebianVersion('1-2')
        apache_dsc = MockPackage('apache', version, dsc, 'sha-1:aaa')

        type_condition = rules.oc([
            rules.rc(eq, 'pdk', 'type', 'deb'),
            rules.rc(eq, 'pdk', 'type', 'udeb')
        ])
        expected = rules.ac([
            rules.rc(eq, 'pdk', 'sp-name', 'apache'),
            rules.rc(eq, 'pdk', 'sp-version', '1-2'), type_condition
        ])

        self.assert_equals(expected, get_dsc_child_condition(apache_dsc))
Пример #16
0
    def test_dont_mutate_meta(self):
        """Make sure the load method does not mutate the meta info
        in the descriptor.
        """
        open('test.xml', 'w').write('''<?xml version="1.0"?>
<component>
  <meta>
    <predicate>object</predicate>
  </meta>
  <contents>
    <dsc>
      <name>a</name>
      <meta>
        <c>d</c>
      </meta>
    </dsc>
    <deb ref="sha-1:aaa">
      <meta>
        <necessity>mandatory</necessity>
      </meta>
    </deb>
  </contents>
</component>
''')
        desc = ComponentDescriptor('test.xml')
        cache = ShamCache()
        cache.add(MockPackage('a', '1', deb, 'sha-1:aaa'))
        desc.load(cache)
        desc.write()
        expected = '''<?xml version="1.0" encoding="utf-8"?>
<component>
  <meta>
    <predicate>object</predicate>
  </meta>
  <contents>
    <dsc>
      <name>a</name>
      <meta>
        <c>d</c>
      </meta>
    </dsc>
    <deb ref="sha-1:aaa">
      <meta>
        <necessity>mandatory</necessity>
      </meta>
    </deb>
  </contents>
</component>
'''
        self.assert_equals_long(expected, open('test.xml').read())
Пример #17
0
    def test_get_general_condition(self):
        version = DebianVersion('1-2')
        apache_dsc = MockPackage('apache', version, dsc, 'sha-1:aaa')

        sp_version = DebianVersion('1-2')
        extra = {
            ('pdk', 'sp-name'): 'one',
            ('pdk', 'sp-version'): sp_version,
            ('deb', 'arch'): 'i386'
        }
        apache_deb = MockPackage('apache', '1-2', deb, 'sha-1:aaa', extra)

        expected = rules.ac([
            rules.rc(eq, 'pdk', 'name', 'apache'),
            rules.rc(eq, 'pdk', 'version', version)
        ])
        self.assert_equals(expected, get_general_condition(apache_dsc))

        expected = rules.ac([
            rules.rc(eq, 'pdk', 'name', 'apache'),
            rules.rc(eq, 'pdk', 'version', version),
            rules.rc(eq, 'pdk', 'arch', 'i386')
        ])
        self.assert_equals(expected, get_general_condition(apache_deb))
Пример #18
0
    def test_get_rpm_child_condition(self):
        version = RPMVersion(version_string='1-2')
        extras = {('pdk', 'source-rpm'): 'apache.src.rpm'}
        apache_rpm = MockPackage('apache',
                                 version,
                                 rpm,
                                 'sha-1:aaa',
                                 extras=extras)

        expected = rules.ac([
            rules.rc(eq, 'pdk', 'filename', 'apache.src.rpm'),
            rules.rc(eq, 'pdk', 'type', 'srpm')
        ])

        self.assert_equals(expected, get_rpm_child_condition(apache_rpm))
Пример #19
0
    def test_load_and_use_star_cond(self):
        """compdesc.load returns a component with packages"""
        os.system('''
cat >a.xml <<EOF
<?xml version="1.0" encoding="utf-8"?>
<component>
  <contents>
    <dsc>
      <name>apache</name>
      <dsc ref="sha-1:ccc">
        <name>apache</name>
      </dsc>
      <deb ref="sha-1:aaa">
        <name>apache</name>
      </deb>
      <deb ref="sha-1:bbb">
        <name>apache-common</name>
      </deb>
    </dsc>
    <dsc>
      <cond><![CDATA[ * apache (>=2) ]]></cond>
    </dsc>
    <src>
      <cond><![CDATA[ * apache (>=2) ]]></cond>
    </src>
    <bin>
      <cond><![CDATA[ * apache-common (>=2) ]]></cond>
    </bin>
  </contents>
</component>
EOF
cp a.xml b.xml
''')
        desc = ComponentDescriptor('a.xml')
        desc.write()
        self.assert_equals_long(open('b.xml').read(), open('a.xml').read())
        condition = desc.contents[1].rule.condition

        a = MockPackage('apache', '2', deb, 'sha-1:aaa')
        b = MockPackage('apache-commmon', '2', deb, 'sha-1:bbb')
        c = MockPackage('apache', '2', dsc, 'sha-1:ccc')
        a.complement = [c]
        b.complement = [c]
        c.complement = [a, b]

        assert condition.evaluate(a)
        assert condition.evaluate(b)
        assert not condition.evaluate(c)

        src_condition = desc.contents[2].rule.condition
        assert src_condition.evaluate(a)
        assert src_condition.evaluate(b)
        assert not src_condition.evaluate(c)
Пример #20
0
    def test_emulation_behaviors(self):
        p = MockPackage('name', '2', deb, extras={('pdk', 'a'): 1})
        self.assert_equal(1, p.pdk.a)
        self.assert_equal('name', p.pdk.name)
        self.assert_equal(DebianVersion('2'), p.pdk.version)

        self.assert_equal(3, len(p))

        try:
            p.z
            self.fail('should have thrown exception')
        except AttributeError:
            pass

        try:
            p['z']
            self.fail('should have thrown exception')
        except KeyError:
            pass
Пример #21
0
    def test_load_file_object(self):
        """compdesc.load returns a component with packages"""
        handle = stringio('''<?xml version="1.0" encoding="utf-8"?>
<component>
  <contents>
    <deb ref="sha-1:aaa"/>
  </contents>
</component>
''')
        desc = ComponentDescriptor('a.xml', handle)
        cache = ShamCache()
        cache.add(MockPackage('a', '1', deb, 'sha-1:aaa'))
        component = desc.load(cache)
        assert isinstance(component, Component)
        self.assert_equal('a.xml', desc.filename)
        self.assert_equal(1, len(list(component.iter_packages())))
        self.assert_equal(1, len(list(component.iter_direct_packages())))
        self.assert_equal(['sha-1:aaa'],
                          [p.blob_id for p in component.iter_packages()])
        self.assert_equal(0, len(list(component.iter_direct_components())))
        self.assert_equal(0, len(list(component.iter_components())))
Пример #22
0
    def set_up(self):
        super(ConditionsAndRulesFixture, self).set_up()
        self.name_condition = rules.rc(eq, 'pdk', 'name', 'a')
        self.version_condition = rules.rc(eq, 'pdk', 'version', '1')
        self.and_condition = rules.ac(
            [self.name_condition, self.version_condition])
        self.or_condition = rules.oc(
            [self.name_condition, self.version_condition])

        self.a1 = MockPackage('a', '1', deb)
        self.a2 = MockPackage('a', '2', deb)
        self.b1 = MockPackage('b', '1', deb)
        self.b2 = MockPackage('b', '2', deb)
        self.c = MockPackage('c', '1', dsc, lang='de')
        self.d = MockPackage('d', '1', dsc, lang='en')
        self.a1.complement.append(self.c)
        self.a2.complement.append(self.d)
Пример #23
0
    def test_get_child_condition(self):
        sp_version = DebianVersion('1-3')
        extra = {
            ('pdk', 'sp-name'): 'apache',
            ('pdk', 'sp-version'): sp_version,
            ('deb', 'arch'): 'i386'
        }
        apache_deb = MockPackage('apache', '1-2', deb, 'sha-1:aaa', extra)

        ref_condition = rules.ac([rules.rc(eq, 'pdk', 'name', 'apache')])
        apache_ref = PackageStanza(deb, 'sha-1:aaa', ref_condition, [])

        parent_condition = rules.ac([
            apache_ref.reference.condition,
            rules.rc(eq, 'pdk', 'version', DebianVersion('1-2'))
        ])
        child_condition = get_deb_child_condition(apache_deb)
        expected_rule = rules.oc([child_condition, parent_condition])
        expected_key_info = ('pdk', 'name', 'apache')
        actual_rule, actual_key_info = get_child_condition(
            apache_deb, apache_ref)
        self.assert_equals(expected_rule, actual_rule)
        self.assert_equals(expected_key_info, actual_key_info)
Пример #24
0
    def test_load(self):
        """compdesc.load returns a component with packages"""
        os.system('''
cat >a.xml <<EOF
<?xml version="1.0" encoding="utf-8"?>
<component>
  <contents>
    <deb ref="sha-1:aaa"/>
  </contents>
</component>
EOF
''')
        desc = ComponentDescriptor('a.xml')
        cache = ShamCache()
        cache.add(MockPackage('a', '1', deb, 'sha-1:aaa'))
        component = desc.load(cache)
        assert isinstance(component, Component)
        self.assert_equal(1, len(list(component.iter_packages())))
        self.assert_equal(1, len(list(component.iter_direct_packages())))
        self.assert_equal(['sha-1:aaa'],
                          [p.blob_id for p in component.iter_packages()])
        self.assert_equal(0, len(list(component.iter_direct_components())))
        self.assert_equal(0, len(list(component.iter_components())))
Пример #25
0
    def test_parse_link(self):
        '''Check that we can parse entities at all.'''
        open('test.xml', 'w').write('''<?xml version="1.0"?>
<component>
  <contents>
    <deb ref="sha-1:aaa">
      <meta>
        <pdk.link>
          <some-meta>can-do</some-meta>
        </pdk.link>
      </meta>
    </deb>
  </contents>
</component>
''')

        desc = ComponentDescriptor('test.xml')
        self.assert_equal([('some-meta', 'can-do')], desc.contents[0].links)
        cache = ShamCache()
        package = MockPackage('a', '1', deb, 'sha-1:aaa')
        cache.add(package)
        comp = desc.load(cache)
        package = comp.iter_packages().next()
        self.assert_equals([('some-meta', 'can-do')], package.links)
Пример #26
0
    def test_dont_lose_entities(self):
        """Make sure the write method handles entities."""
        open('test.xml', 'w').write('''<?xml version="1.0"?>
<component>
  <meta>
    <predicate>object</predicate>
  </meta>
  <contents>
    <dsc>
      <name>a</name>
      <meta>
        <c>d</c>
      </meta>
    </dsc>
    <deb ref="sha-1:aaa">
      <meta>
        <necessity>mandatory</necessity>
      </meta>
    </deb>
  </contents>
  <entities>
    <test id="1">
      <a>b</a>
      <c>d</c>
      <e>f</e>
    </test>
  </entities>
</component>
''')
        desc = ComponentDescriptor('test.xml')
        cache = ShamCache()
        cache.add(MockPackage('a', '1', deb, 'sha-1:aaa'))
        desc.load(cache)
        desc.write()
        expected = '''<?xml version="1.0" encoding="utf-8"?>
<component>
  <meta>
    <predicate>object</predicate>
  </meta>
  <contents>
    <dsc>
      <name>a</name>
      <meta>
        <c>d</c>
      </meta>
    </dsc>
    <deb ref="sha-1:aaa">
      <meta>
        <necessity>mandatory</necessity>
      </meta>
    </deb>
  </contents>
  <entities>
    <test id="1">
      <a>b</a>
      <c>d</c>
      <e>f</e>
    </test>
  </entities>
</component>
'''
        self.assert_equals_long(expected, open('test.xml').read())
Пример #27
0
 def test_package_is_hashable(self):
     p = MockPackage('a', '1', deb)
     Set([p])
Пример #28
0
 def make_package(name, version, arch, package_type):
     return MockPackage(name, version, package_type, arch=arch)
Пример #29
0
    def test_load_multilevel(self):
        """test loading a component that refers to another"""
        os.system('''
cat >a.xml <<EOF
<?xml version="1.0" encoding="utf-8"?>
<component>
  <contents>
    <deb>
      <name>libc6</name>
      <meta>
        <necessity>mandatory</necessity>
      </meta>
    </deb>
    <deb>
      <name>apache</name>
      <meta>
        <necessity>default</necessity>
      </meta>
    </deb>
    <component>b.xml</component>
  </contents>
</component>
EOF
''')
        os.system('''
cat >b.xml <<EOF
<?xml version="1.0" encoding="utf-8"?>
<component>
  <contents>
    <deb>
      <name>libc6</name>
      <meta>
        <necessity>optional</necessity>
      </meta>
    </deb>
    <deb ref="sha-1:aaa">
      <name>apache</name>
      <meta>
        <necessity>optional</necessity>
      </meta>
    </deb>
    <component>c.xml</component>
  </contents>
</component>
EOF
''')
        os.system('''
cat >c.xml <<EOF
<?xml version="1.0" encoding="utf-8"?>
<component>
  <contents>
    <deb ref="sha-1:bbb">
      <name>libc6</name>
      <meta>
        <necessity>mandatory</necessity>
        <some-random-key>42</some-random-key>
      </meta>
    </deb>
  </contents>
</component>
EOF
''')

        apache = MockPackage('apache', '1', deb, 'sha-1:aaa')
        libc = MockPackage('libc6', '1', deb, 'sha-1:bbb')
        cache = ShamCache()
        cache.add(apache)
        cache.add(libc)

        desc_b = ComponentDescriptor('b.xml')
        component_b = desc_b.load(cache)
        assert isinstance(component_b, Component)
        self.assert_equal('b.xml', desc_b.filename)
        self.assert_equal('b.xml', component_b.ref)
        self.assert_equal(2, len(list(component_b.iter_packages())))
        self.assert_equal(['sha-1:aaa', 'sha-1:bbb'],
                          [p.blob_id for p in component_b.iter_packages()])
        self.assert_equal(1, len(list(component_b.iter_direct_packages())))
        self.assert_equal(1, len(list(component_b.iter_direct_components())))
        self.assert_equal(1, len(list(component_b.iter_components())))
        self.assert_equal('optional', libc['pdk', 'necessity'])
        self.assert_equal('optional', apache['pdk', 'necessity'])

        apache = MockPackage('apache', '1', deb, 'sha-1:aaa')
        libc = MockPackage('libc6', '1', deb, 'sha-1:bbb')
        cache = ShamCache()
        cache.add(apache)
        cache.add(libc)

        desc_a = ComponentDescriptor('a.xml')
        component_a = desc_a.load(cache)
        assert isinstance(component_a, Component)
        self.assert_equal(2, len(list(component_a.iter_packages())))
        self.assert_equal(['sha-1:aaa', 'sha-1:bbb'],
                          [p.blob_id for p in component_a.iter_packages()])
        self.assert_equal(0, len(list(component_a.iter_direct_packages())))
        self.assert_equal(1, len(list(component_a.iter_direct_components())))
        self.assert_equal(2, len(list(component_a.iter_components())))
        self.assert_equal('mandatory', libc['pdk', 'necessity'])
        self.assert_equal('default', apache['pdk', 'necessity'])
        self.assert_equal('42', libc['pdk', 'some-random-key'])