class Test_Config(test_helper.MoxTestCase): def setUp(self): super(Test_Config, self).setUp() self.c = Config() def test_addition_and_retrieval(self): foo_stanza1 = self.mox.CreateMock(ConfigStanza) foo_stanza1.get('package').AndReturn('foo') foo_stanza2 = self.mox.CreateMock(ConfigStanza) foo_stanza2.get('package').AndReturn('foo') bar_stanza = self.mox.CreateMock(ConfigStanza) bar_stanza.get('package').AndReturn('bar') self.mox.ReplayAll() self.c.add(foo_stanza1) self.c.add(foo_stanza2) self.c.add(bar_stanza) foo_stanzas = self.c.package('foo') bar_stanzas = self.c.package('bar') baz_stanzas = self.c.package('baz') self.assertEquals(len(foo_stanzas), 2) self.assertEquals(foo_stanzas[0], foo_stanza1) self.assertEquals(foo_stanzas[1], foo_stanza2) self.assertEquals(len(bar_stanzas), 1) self.assertEquals(bar_stanzas[0], bar_stanza) self.assertEquals(len(baz_stanzas), 0)
def test_non_verbose_empty_config(self): # libc6 - never self.reporter.report( mox.Func(lambda o: o.package_name == 'libspf')).InAnyOrder() # libfoobar - never self.reporter.report( mox.Func(lambda o: o.package_name == 'git-core')).InAnyOrder() self.mox.ReplayAll() self.finishSetUp() checker = Checker(self.facter) policy = Policy(self.apt_pkg_adapter, self.facter, Config()) self.cache_adapter.run(checker, policy, self.package_adapter_factory)
def finishSetUp(self): self.apt_pkg_adapter = AptPkgAdapter(self.apt_pkg) self.apt_pkg_adapter.init() cache_adapter_factory = CacheAdapterFactory() self.package_adapter_factory = PackageAdapterFactory( DepCacheAdapter(self.apt_depcache)) self.cache_adapter = self.apt_pkg_adapter.get_cache_adapter( cache_adapter_factory, self.reporter, self.mock_progress) config_finder = ConfigFinder('test-data/config') config_parser = ConfigParser() self.config = Config() for path, file in config_finder: config_parser.load(file, self.config)
def run(verbose): facter = Facter() reporter = Reporter() apt_pkg_adapter = AptPkgAdapter(apt_pkg) apt_pkg_adapter.init() cache_adapter = apt_pkg_adapter.get_cache_adapter(CacheAdapterFactory(), reporter, NullProgress()) apt_depcache_adapter = apt_pkg_adapter.get_depcache_adapter( DepCacheAdapterFactory()) package_adapter_factory = PackageAdapterFactory(apt_depcache_adapter) checker = Checker(facter, verbose) config = Config() config_finder = ConfigFinder('/etc/apt/forktracer.conf', '/etc/apt/forktracer.d') config_parser = ConfigParser() for path, file in config_finder: config_parser.load(file, config) if verbose: policy = VerbosePolicy() else: policy = Policy(apt_pkg_adapter, facter, config) cache_adapter.run(checker, policy, package_adapter_factory)
def setUp(self): super(Test_Config, self).setUp() self.c = Config()