def test_pattern(self): infoq_client = client.InfoQ(cache_enabled=True) summary = next(scrap.get_summaries(infoq_client)) # Nowadays, the /presentations page contains more than 10 entries output = self.run_cmd(self.default_cmd + ["-p", summary['title']]) self.assertEqual(output.count("Id: "), 1)
def test_clear(self): # Ensure there is at least one file in the cache dir infoq_client = client.InfoQ(cache_enabled=True) infoq_client.cache.put_content("testfile", b"content") # Backup the cache dir backup_dir = infoq_client.cache.dir tmp_dir = os.path.join(tempfile.mkdtemp(), os.path.basename(backup_dir)) shutil.copytree(backup_dir, tmp_dir) try: self.run_cmd(self.default_args) self.assertFalse(os.path.exists(backup_dir)) # Now restore the cache dir shutil.copytree(tmp_dir, backup_dir) finally: shutil.rmtree(os.path.dirname(tmp_dir))
def main(): # Required when stdout is piped if not sys.stdout.encoding: import codecs import locale sys.stdout = codecs.getwriter(locale.getpreferredencoding())( sys.stdout) modules = { PresentationModule.name: PresentationModule, CacheModule.name: CacheModule } parser = argparse.ArgumentParser(prog="infoqscraper") parser.add_argument('-c', '--cache', action="store_true", help="Enable disk caching.") parser.add_argument('-V', '--version', action="version", help="Display version", version="%s %s" % (app_name, app_version)) parser.add_argument('module', choices=list(modules.keys())) parser.add_argument('module_args', nargs=argparse.REMAINDER) args = parser.parse_args() infoq_client = client.InfoQ(cache_enabled=args.cache) try: module_class = modules[args.module] except KeyError: return warn("%s: '%s' is not a module. See '%s --help'" % (app_name, args.module, app_name)) module = module_class() try: return module.main(infoq_client, args.module_args) except (ArgumentError, CommandError) as e: return warn(e)
def setUp(self): self.iq = client.InfoQ()
def setUp(self): self.iq = client.InfoQ() self.tmp_dir = tempfile.mkdtemp()