def testUsageContainCommand(self, command): ob = CygAptOb(True); try: self.obj.usage(); finally: ret = ob.getClean(); self.assertTrue(" {0}".format(command) in ret);
def testUsageContainCommand(self, command): ob = CygAptOb(True) try: self.obj.usage() finally: ret = ob.getClean() self.assertTrue(" {0}".format(command) in ret)
def testChecksum(self): self.obj.download(); ob = CygAptOb(True); try: self.obj.checksum(); finally: ret = ob.getClean(); lines = ret.splitlines(); self.assertEqual(2, len(lines)); self.assertEqual(lines[0], lines[1]);
def testChecksum(self): self.obj.download() ob = CygAptOb(True) try: self.obj.checksum() finally: ret = ob.getClean() lines = ret.splitlines() self.assertEqual(2, len(lines)) self.assertEqual(lines[0], lines[1])
def testFind(self): pkgname = self._var_setupIni.libpkg.name self.testInstall(pkgname) self.obj.setPkgName("version") expected = "{0}: {1}\n".format(pkgname, "/var/" + pkgname + "/version") ob = CygAptOb(True) self.obj.find() ret = ob.getClean() self.assertEqual(ret, expected)
def testSearch(self): self.obj.setPkgName("libp") expected = "{0} - {1}\n".format( self._var_setupIni.libpkg.name, self._var_setupIni.libpkg.shortDesc.replace('"', '')) ob = CygAptOb(True) self.obj.search() ret = ob.getClean() self.assertEqual(ret, expected)
def testSearch(self): self.obj.setPkgName("libp"); expected = "{0} - {1}\n".format( self._var_setupIni.libpkg.name, self._var_setupIni.libpkg.shortDesc.replace('"','') ); ob = CygAptOb(True); self.obj.search(); ret = ob.getClean(); self.assertEqual(ret, expected);
def testFind(self): self.testDoInstall(); self.obj.setPkgName("version"); pkgname = self._var_setupIni.pkg.name; expected = "{0}: {1}\n".format( pkgname, os.path.join("/var", pkgname, "version") ); ob = CygAptOb(True); self.obj.find(); ret = ob.getClean(); self.assertEqual(ret, expected);
def testFind(self): pkgname = self._var_setupIni.libpkg.name; self.testInstall(pkgname); self.obj.setPkgName("version"); expected = "{0}: {1}\n".format( pkgname, "/var/"+pkgname+"/version" ); ob = CygAptOb(True); self.obj.find(); ret = ob.getClean(); self.assertEqual(ret, expected);
def main(self): main_downloads = None; main_dists = 0; main_installed = 0; main_packagename = None; main_cyg_apt_rc = None; home_cyg_apt_rc = None; main_verbose = False; main_cygwin_p = (sys.platform == "cygwin"); cas = CygAptSetup(main_cygwin_p, main_verbose); update_not_needed = [ "ball", "find", "help", "purge", "remove", "version", "filelist", "update", "setup", "md5", ]; ob = CygAptOb(True); cas.usage(); usage = ob.getFlush(); cap = CygAptArgParser(usage=usage, scriptname=self.getAppName()); args = cap.parse(); main_command = args.command; main_files = args.package[:]; main_files.insert(0, main_command); if len(args.package) > 0: main_packagename = args.package[0]; else: main_packagename = None; main_verbose = args.verbose; main_download_p = args.download_p; main_mirror = args.mirror; main_distname = args.distname; main_noupdate = args.noupdate; main_nodeps_p = args.nodeps_p; main_regex_search = args.regex_search; main_nobarred = args.force; main_verify = args.verify; main_nopostinstall = args.nopostinstall; main_nopostremove = args.nopostremove; cas.setVerbose(main_verbose); # Take most of our configuration from .cyg-apt # preferring .cyg-apt in current directory over $(HOME)/.cyg-apt cwd_cyg_apt_rc = os.path.join( os.getcwd(), ".{0}".format(self.getAppName()) ); if os.path.exists(cwd_cyg_apt_rc): main_cyg_apt_rc = cwd_cyg_apt_rc; elif "HOME" in os.environ: home_cyg_apt_rc = os.path.join( os.environ['HOME'], ".{0}".format(self.getAppName()) ); if os.path.exists(home_cyg_apt_rc): main_cyg_apt_rc = home_cyg_apt_rc; if main_cyg_apt_rc: # Take our configuration from .cyg-apt # Command line options can override, but only for this run. main_cyg_apt_rc = main_cyg_apt_rc.replace("\\","/"); elif (main_command != "setup"): print( "{0}: no .{0}: run \"{0} setup\"".format(self.getAppName()), file=sys.stderr ); return 1; if (main_command == "setup"): cas.setup(args.force); return 0; elif (main_command == "help"): cas.usage(main_cyg_apt_rc); return 0; elif (main_command == "update"): cas.update(main_cyg_apt_rc, main_verify, main_mirror=main_mirror); return 0; always_update = cautils.parse_rc(main_cyg_apt_rc); always_update = always_update and\ main_command not in update_not_needed and\ not main_noupdate; if always_update: cas.update(main_cyg_apt_rc, main_verify, main_mirror=main_mirror); if main_command and main_command in dir(CygApt): cyg_apt = CygApt( main_packagename, main_files, main_cyg_apt_rc, main_cygwin_p, main_download_p, main_mirror, main_downloads, main_distname, main_nodeps_p, main_regex_search, main_nobarred, main_nopostinstall, main_nopostremove, main_dists, main_installed, self.getAppName(), main_verbose ); getattr(cyg_apt, main_command)(); else: cas.usage(main_cyg_apt_rc); return 0;
def setUp(self): TestCase.setUp(self) self.obj = CygAptOb(False)
class TestOb(TestCase): def setUp(self): TestCase.setUp(self) self.obj = CygAptOb(False) def tearDown(self): self.obj._end() TestCase.tearDown(self) def makeOn(self): txt = "TestOb.makeOn " print(txt, end="") value = sys.stdout.getvalue() self.assertTrue(value.endswith(txt)) self.assertTrue(self.obj._state) def makeOff(self): self.assertEqual(repr(sys.stdout), REPR_STDOUT) self.assertFalse(self.obj._state) def test__init__(self): self.assertTrue(isinstance(self.obj, CygAptOb)) def testClean(self): self.obj.clean() self.makeOff() self.obj.start() self.makeOn() self.obj.clean() self.assertEqual(self.obj._buffer.getvalue(), "") self.assertNotEqual(self.obj._value, "") self.assertNotEqual(self.obj.getContents(), "") def testStartEnd(self): self.obj._end() self.makeOff() self.obj.start() self.makeOn() self.obj._end() self.makeOff() def testEndClean(self): self.obj.endClean() self.makeOff() self.obj.start() self.makeOn() self.obj.endClean() self.makeOff() def testEndFlush(self): self.obj.endFlush() self.makeOff() self.obj.start() self.makeOn() self.obj.endFlush() self.makeOff() def testFlush(self): self.obj.flush() self.makeOff() self.obj.start() self.makeOn() self.obj.flush() self.makeOn() def testGetClean(self): ret = self.obj.getClean() self.assertFalse(ret) self.makeOff() self.obj.start() self.makeOn() t = self.obj._buffer.getvalue() txt = "TestOb.test_getClean" print(txt) ret = self.obj.getClean() self.assertEqual(ret, "{0}{1}\n".format(t, txt)) self.makeOff() def testGetContent(self): ret = self.obj.getContents() self.assertFalse(ret) self.makeOff() self.obj.start() txt = "TestOb.test_get_content" print(txt) ret = self.obj.getContents() self.assertEqual(ret, "{0}\n".format(txt)) self.makeOn() def testGetFlush(self): ret = self.obj.getFlush() self.assertFalse(ret) self.makeOff() self.obj.start() txt = "TestOb.test_getFlush" print(txt) ret = self.obj.getFlush() self.assertEqual(ret, "{0}\n".format(txt)) self.makeOff() def testGetLength(self): ret = self.obj.getLength() self.assertFalse(ret) self.makeOff() self.obj.start() length = 10 print("t" * length) ret = self.obj.getLength() self.assertEqual(ret, length + 1) self.makeOn() def testImplicitFlush(self): self.obj.implicitFlush(True) self.makeOff() self.obj.implicitFlush(False) self.makeOn()
def setUp(self): unittest.TestCase.setUp(self); self.obj = CygAptOb(False);
class TestOb(unittest.TestCase): def setUp(self): unittest.TestCase.setUp(self); self.obj = CygAptOb(False); def tearDown(self): unittest.TestCase.tearDown(self); self.obj._end(); def makeOn(self): txt = "TestOb.makeOn "; print(txt, end=""); value = sys.stdout.getvalue(); self.assertTrue(value.endswith(txt)); self.assertTrue(self.obj._state); def makeOff(self): self.assertEqual(repr(sys.stdout), REPR_STDOUT); self.assertFalse(self.obj._state); def test__init__(self): self.assertTrue(isinstance(self.obj, CygAptOb)); def testClean(self): self.obj.clean(); self.makeOff(); self.obj.start(); self.makeOn(); self.obj.clean(); self.assertEqual(self.obj._buffer.getvalue(), ""); self.assertNotEqual(self.obj._value, ""); self.assertNotEqual(self.obj.getContents(), ""); def testStartEnd(self): self.obj._end(); self.makeOff(); self.obj.start(); self.makeOn(); self.obj._end(); self.makeOff(); def testEndClean(self): self.obj.endClean(); self.makeOff(); self.obj.start(); self.makeOn(); self.obj.endClean(); self.makeOff(); def testEndFlush(self): self.obj.endFlush(); self.makeOff(); self.obj.start(); self.makeOn(); self.obj.endFlush(); self.makeOff(); def testFlush(self): self.obj.flush(); self.makeOff(); self.obj.start(); self.makeOn(); self.obj.flush(); self.makeOn(); def testGetClean(self): ret = self.obj.getClean(); self.assertFalse(ret); self.makeOff(); self.obj.start(); self.makeOn(); t = self.obj._buffer.getvalue(); txt = "TestOb.test_getClean"; print(txt); ret = self.obj.getClean(); self.assertEqual(ret, "{0}{1}\n".format(t, txt)); self.makeOff(); def testGetContent(self): ret = self.obj.getContents(); self.assertFalse(ret); self.makeOff(); self.obj.start(); txt = "TestOb.test_get_content"; print(txt); ret = self.obj.getContents(); self.assertEqual(ret, "{0}\n".format(txt)); self.makeOn(); def testGetFlush(self): ret = self.obj.getFlush(); self.assertFalse(ret); self.makeOff(); self.obj.start(); txt = "TestOb.test_getFlush"; print(txt); ret = self.obj.getFlush(); self.assertEqual(ret, "{0}\n".format(txt)); self.makeOff(); def testGetLength(self): ret = self.obj.getLength(); self.assertFalse(ret); self.makeOff(); self.obj.start(); length = 10; print("t" * length); ret = self.obj.getLength(); self.assertEqual(ret, length + 1); self.makeOn(); def testImplicitFlush(self): self.obj.implicitFlush(True); self.makeOff(); self.obj.implicitFlush(False); self.makeOn();
def setUp(self): TestCase.setUp(self); self.obj = CygAptOb(False);