コード例 #1
0
ファイル: test_component.py プロジェクト: 64studio/pdk
    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')])
コード例 #2
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')])
コード例 #3
0
ファイル: test_component.py プロジェクト: 64studio/pdk
    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)
コード例 #4
0
ファイル: test_component.py プロジェクト: 64studio/pdk
    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())
コード例 #5
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())
コード例 #6
0
ファイル: test_component.py プロジェクト: 64studio/pdk
    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)
コード例 #7
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())))
コード例 #8
0
ファイル: test_component.py プロジェクト: 64studio/pdk
    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())))
コード例 #9
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)
コード例 #10
0
ファイル: test_component.py プロジェクト: 64studio/pdk
    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())))
コード例 #11
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())))
コード例 #12
0
    def test_bad_comp_ref(self):
        os.system('''
cat >a.xml <<EOF
<?xml version="1.0" encoding="utf-8"?>
<component>
  <contents>
    <component>
      <limit><![CDATA[ apache ]]></limit>
    </component>
  </contents>
</component>
EOF
''')
        try:
            ComponentDescriptor('a.xml').load(ShamCache())
            self.fail('should have thrown exception')
        except InputError:
            pass

        os.system('''
cat >a.xml <<EOF
<?xml version="1.0" encoding="utf-8"?>
<component>
  <contents>
    <component>
      <zzz></zzz>
      <limit><![CDATA[ apache ]]></limit>
    </component>
  </contents>
</component>
EOF
''')
        try:
            ComponentDescriptor('a.xml').load(ShamCache())
            self.fail('should have thrown exception')
        except InputError, error:
            assert '"zzz"' in str(error)
コード例 #13
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)
コード例 #14
0
ファイル: test_component.py プロジェクト: 64studio/pdk
    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)
コード例 #15
0
    def test_parse_entity(self):
        '''Check that we can parse entities at all.'''
        open('test.xml', 'w').write('''<?xml version="1.0"?>
<component>
  <entities>
    <some-ent id="can-do">
      <a.name>hello</a.name>
      <b.description>whodo whodo whodo</b.description>
    </some-ent>
  </entities>
</component>
''')

        desc = ComponentDescriptor('test.xml')
        entity1 = desc.entities[('some-ent', 'can-do')]
        self.assert_equal('hello', entity1[('a', 'name')])
        self.assert_equal('whodo whodo whodo', entity1[('b', 'description')])
        cache = ShamCache()
        comp = desc.load(cache)
        entity2 = comp.entities[('some-ent', 'can-do')]
        self.assert_equal('hello', entity2[('a', 'name')])
        self.assert_equal('whodo whodo whodo', entity2[('b', 'description')])
コード例 #16
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)
コード例 #17
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'])
コード例 #18
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())
コード例 #19
0
ファイル: test_component.py プロジェクト: 64studio/pdk
    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())
コード例 #20
0
ファイル: test_component.py プロジェクト: 64studio/pdk
    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'])