Exemplo n.º 1
0
    def test(self):
        buf = StringIO()
        sw = utils.ShellWriter(buf)
        sw.Write("#!/bin/bash")
        sw.Write("if true; then")
        sw.IncIndent()
        try:
            sw.Write("echo true")

            sw.Write("for i in 1 2 3")
            sw.Write("do")
            sw.IncIndent()
            try:
                self.assertEqual(sw._indent, 2)
                sw.Write("date")
            finally:
                sw.DecIndent()
            sw.Write("done")
        finally:
            sw.DecIndent()
        sw.Write("echo %s", utils.ShellQuote("Hello World"))
        sw.Write("exit 0")

        self.assertEqual(sw._indent, 0)

        output = buf.getvalue()

        self.assertTrue(output.endswith("\n"))

        lines = output.splitlines()
        self.assertEqual(len(lines), 9)
        self.assertEqual(lines[0], "#!/bin/bash")
        self.assertTrue(re.match(r"^\s+date$", lines[5]))
        self.assertEqual(lines[7], "echo 'Hello World'")
Exemplo n.º 2
0
    def testEmptyLinesNoIndent(self):
        buf = StringIO()
        sw = utils.ShellWriter(buf, indent=False)

        self._AddLevel(sw, 1)

        self.assertEqual(buf.getvalue(),
                         "".join("\n%s\n" % i for i in range(1, 6)))
Exemplo n.º 3
0
    def testEmptyLines(self):
        buf = StringIO()
        sw = utils.ShellWriter(buf)

        self._AddLevel(sw, 1)

        self.assertEqual(
            buf.getvalue(),
            "".join("\n%s%s\n" % (i * "  ", i) for i in range(1, 6)))
Exemplo n.º 4
0
 def testEmptyNoIndent(self):
     buf = StringIO()
     sw = utils.ShellWriter(buf, indent=False)
     sw = None
     self.assertEqual(buf.getvalue(), "")
Exemplo n.º 5
0
 def testEmpty(self):
     buf = StringIO()
     sw = utils.ShellWriter(buf)
     sw = None
     self.assertEqual(buf.getvalue(), "")