
Create the channel.

  >>> from tests import *
  >>> from smart.channel import createChannel
  >>> channel = createChannel("alias",
  ...                         {"type": "rpm-md",
  ...                          "baseurl": "file://%s/yumrpm" % TESTDATADIR})
  >>> channel
  <smart.channels.rpm_md.RPMMetaDataChannel object at ...>


We need a progress and a fetcher.

  >>> from smart.progress import Progress
  >>> from smart.fetcher import Fetcher
  >>> progress = Progress()
  >>> fetcher = Fetcher()


Fetch channel data.

  >>> channel.fetch(fetcher, progress)
  True
  >>> channel.getLoaders()
  [<smart.backends.rpm.metadata.RPMMetaDataLoader object at ...>]


Let's create a cache to put the loader in, so that we can test it.

  >>> from smart.cache import Cache
  >>> loader = channel.getLoaders()[0]
  >>> cache = Cache()
  >>> cache.addLoader(loader)


The setup is ready. Now we can load the data into the cache.

  >>> cache.load()


This should give us one package with the data we already know.

  >>> packages = sorted(cache.getPackages())
  >>> packages
  [name1-version1-release1@noarch, name2-version2-release2@noarch]

  >>> pkg = packages[0]
  >>> type(pkg)
  <class 'smart.backends.rpm.base.RPMPackage'>

Let's inspect the package data.

  >>> pkg.name
  'name1'
  >>> pkg.version
  'version1-release1@noarch'

  >>> sorted(pkg.provides)
  [name1 = version1-release1@noarch, providename1 = provideversion1]
  >>> [type(x).__name__ for x in sorted(pkg.provides)]
  ['RPMNameProvides', 'RPMProvides']

  >>> sorted(pkg.requires)
  [/bin/sh, prerequirename1 = prerequireversion1, requirename1 = requireversion1]
  >>> # XXX pre-requires are broken in createrepo
  >>> [type(x).__name__ for x in sorted(pkg.requires)]
  ['RPMPreRequires', 'RPMPreRequires', 'RPMPreRequires']

  >>> sorted(pkg.upgrades)
  [name1 < version1-release1@noarch, obsoletesname1 = obsoletesversion1]
  >>> [type(x).__name__ for x in sorted(pkg.upgrades)]
  ['RPMObsoletes', 'RPMObsoletes']

  >>> sorted(pkg.conflicts)
  [conflictsname1 = conflictsversion1, obsoletesname1 = obsoletesversion1]
  >>> [type(x).__name__ for x in sorted(pkg.conflicts)]
  ['RPMConflicts', 'RPMObsoletes']



Now let's ask the loader for a PackageInfo instance, and inspect it.

  >>> info = loader.getInfo(pkg)
  >>> type(info)
  <class 'smart.backends.rpm.metadata.RPMMetaDataPackageInfo'>

  >>> info.getGroup()
  'Group1'
  >>> info.getSummary()
  'Summary1'

  >>> info.getDescription()
  'Description1'

  >>> info.getURLs()
  ['file:///.../tests/data/yumrpm/name1-version1-release1.noarch.rpm']
  >>> url = info.getURLs()[0]

  >>> info.getSHA(url)
  >>> info.getSHA256(url)
  '705cb36fe89d15f6e6aeacb6d80812d8deec2126b9c146ad4199a86fa919b82f'
  >>> info.getSize(url)
  2160


vim:ft=doctest
