def test_sample(self):
        basedir = os.path.join(self.make_basedir(), "node1")
        self.createNode(basedir)
        n = self.startNode(basedir)
        d = self.cliMustSucceed("open", "-n", "-d", basedir)
        # test "petmail sample -d BASEDIR"
        d.addCallback(lambda _: self.cliMustSucceed("sample", "-d", basedir))
        d.addCallback(lambda res: self.failUnlessEqual(res, "sample ok\n"))
        d.addCallback(lambda _: self.failUnlessEqual(n.agent._debug_sample,
                                                     "no data"))
        d.addCallback(lambda _: self.cliMustSucceed("sample", "-d", basedir,
                                                    "-o", "other data"))
        d.addCallback(lambda res: self.failUnlessEqual(res, "sample ok object\n"))
        d.addCallback(lambda _: self.failUnlessEqual(n.agent._debug_sample,
                                                     "other data"))
        d.addCallback(lambda _: self.cli("sample", "-d", basedir, "--error"))
        def _fail1((out,err,rc)):
            self.failIfEqual(rc, 0)
            self.failUnlessEqual(out, "")
            self.failUnlessEqual(err,
                                 "HTTP status: 400 command error\n"+
                                 "sample error text\n")
        d.addCallback(_fail1)

        # Also test --server-error . This raises a ValueError inside the
        # server, which we must eat to keep the test framework from thinking
        # an error went unhandled.
        d.addCallback(lambda _: self.cli("sample", "-d", basedir,
                                         "--server-error"))
        def _fail2((out,err,rc)):
            self.failIfEqual(rc, 0)
            self.failUnlessEqual(out, "")
            self.failUnlessEqual(err,
                                 "HTTP status: 500 Internal Server Error\n"+
                                 "Please see node logs for details\n")
            self.flushLoggedErrors(SampleError)
        d.addCallback(_fail2)

        # test "petmail -d BASEDIR sample" too
        d.addCallback(lambda _: self.cliMustSucceed("-d", basedir, "sample"))
        d.addCallback(lambda res: self.failUnlessEqual(res, "sample ok\n"))

        return d
dataset/ETHPy150Open warner/petmail/petmail/test/test_node.py/CLI.test_sample/original