def test_parseOptionsHelp(self): """ L{Start.parseOptions} writes usage information to stdout if C{"--help"} is in the argument list it is passed and L{twistd.run} is not called. """ start = axiomatic.Start() start.run = None original = sys.stdout sys.stdout = stdout = io.StringIO() try: self.assertRaises(SystemExit, start.parseOptions, ["--help"]) finally: sys.stdout = original # Some random options that should be present. This is a bad test # because we don't control what C{opt_help} actually does and we don't # even really care as long as it's the same as what I{twistd --help} # does. We could try running them both and comparing, but then we'd # still want to do some sanity check against one of them in case we end # up getting the twistd version incorrectly somehow... -exarkun self.assertIn("--reactor", stdout.getvalue()) if not platform.isWindows(): # This isn't an option on Windows, so it shouldn't be there. self.assertIn("--uid", stdout.getvalue()) # Also, we don't want to see twistd plugins here. self.assertNotIn("axiomatic-start", stdout.getvalue())
def test_parseOptions(self): """ L{Start.parseOptions} adds axiomatic-suitable defaults for any unspecified parameters and then calls L{twistd.run} with the modified argument list. """ argv = [] def fakeRun(): argv.extend(sys.argv) options = axiomatic.Options() options['dbdir'] = dbdir = self.mktemp() start = axiomatic.Start() start.parent = options start.run = fakeRun original = sys.argv[:] try: start.parseOptions(["-l", "foo", "--pidfile", "bar"]) finally: sys.argv[:] = original self.assertEqual(argv, [ sys.argv[0], "-l", "foo", "--pidfile", "bar", "axiomatic-start", "--dbdir", os.path.abspath(dbdir) ])
def test_getArguments(self): """ L{Start.getArguments} adds a I{--pidfile} argument if one is not present and a I{--logfile} argument if one is not present and daemonization is enabled and adds a I{--dbdir} argument pointing at the store it is passed. """ dbdir = FilePath(self.mktemp()) store = Store(dbdir) run = self._getRunDir(dbdir) logs = self._getLogDir(dbdir) start = axiomatic.Start() logfileArg = ["--logfile", logs.child("axiomatic.log").path] # twistd on Windows doesn't support PID files, so on Windows, # getArguments should *not* add --pidfile. if platform.isWindows(): pidfileArg = [] else: pidfileArg = ["--pidfile", run.child("axiomatic.pid").path] restArg = ["axiomatic-start", "--dbdir", dbdir.path] self.assertEqual(start.getArguments(store, []), logfileArg + pidfileArg + restArg) self.assertEqual(start.getArguments(store, ["--logfile", "foo"]), ["--logfile", "foo"] + pidfileArg + restArg) self.assertEqual(start.getArguments(store, ["-l", "foo"]), ["-l", "foo"] + pidfileArg + restArg) self.assertEqual(start.getArguments(store, ["--nodaemon"]), ["--nodaemon"] + pidfileArg + restArg) self.assertEqual(start.getArguments(store, ["-n"]), ["-n"] + pidfileArg + restArg) self.assertEqual(start.getArguments(store, ["--pidfile", "foo"]), ["--pidfile", "foo"] + logfileArg + restArg)
def test_logDirectoryCreated(self): """ If L{Start.getArguments} adds a I{--logfile} argument, it creates the necessary directory. """ dbdir = FilePath(self.mktemp()) store = Store(dbdir) start = axiomatic.Start() start.getArguments(store, ["-l", "foo"]) self.assertFalse(self._getLogDir(dbdir).exists()) start.getArguments(store, []) self.assertTrue(self._getLogDir(dbdir).exists())