Example #1
0
    def test_dry_run(self):
        shell.dry_run = True

        basedir = os.getcwd()
        foobar_dir = os.path.join(self.tmpdir, 'foo', 'bar')

        shell.makedirs(foobar_dir)
        self.assertFalse(os.path.exists(os.path.join(self.tmpdir, 'foo')))
        self.assertFalse(os.path.exists(foobar_dir))

        with shell.pushd(foobar_dir):
            self.assertEqual(os.getcwd(), basedir)
            shell.call(['touch', 'testfile'])
            self.assertFalse(
                os.path.exists(os.path.join(foobar_dir, 'testfile')))

        self.assertEqual(os.getcwd(), basedir)

        shell.rmtree(self.tmpdir)
        self.assertTrue(os.path.exists(self.tmpdir))

        self.assertEqual(
            self.stdout.getvalue(), '''\
+ mkdir -p {foobar_dir}
+ pushd {foobar_dir}
+ touch testfile
+ popd
+ rm -rf {tmpdir}
'''.format(foobar_dir=foobar_dir, tmpdir=self.tmpdir))
        self.assertEqual(self.stderr.getvalue(), "")
        self.dry_run = False
Example #2
0
    def test_dry_run(self):
        shell.dry_run = True

        basedir = os.getcwd()
        foobar_dir = os.path.join(self.tmpdir, "foo", "bar")

        shell.makedirs(foobar_dir)
        self.assertFalse(os.path.exists(os.path.join(self.tmpdir, "foo")))
        self.assertFalse(os.path.exists(foobar_dir))

        with shell.pushd(foobar_dir):
            self.assertEqual(os.getcwd(), basedir)
            shell.call(["touch", "testfile"])
            self.assertFalse(os.path.exists(os.path.join(foobar_dir, "testfile")))

        self.assertEqual(os.getcwd(), basedir)

        shell.rmtree(self.tmpdir)
        self.assertTrue(os.path.exists(self.tmpdir))

        self.assertEqual(
            self.stdout.getvalue(),
            """\
+ mkdir -p {foobar_dir}
+ pushd {foobar_dir}
+ touch testfile
+ popd
+ rm -rf {tmpdir}
""".format(
                foobar_dir=foobar_dir, tmpdir=self.tmpdir
            ),
        )
        self.assertEqual(self.stderr.getvalue(), "")
        self.dry_run = False
Example #3
0
    def test_dry_run(self):
        shell.dry_run = True

        basedir = os.getcwd()
        foobar_dir = os.path.join(self.tmpdir, 'foo', 'bar')

        shell.makedirs(foobar_dir)
        self.assertFalse(os.path.exists(os.path.join(self.tmpdir, 'foo')))
        self.assertFalse(os.path.exists(foobar_dir))

        with shell.pushd(foobar_dir):
            self.assertEqual(os.getcwd(), basedir)
            shell.call(['touch', 'testfile'])
            self.assertFalse(os.path.exists(
                os.path.join(foobar_dir, 'testfile')))

        self.assertEqual(os.getcwd(), basedir)

        shell.rmtree(self.tmpdir)
        self.assertTrue(os.path.exists(self.tmpdir))

        self.assertEqual(self.stdout.getvalue(), '''\
+ mkdir -p {foobar_dir}
+ pushd {foobar_dir}
+ touch testfile
+ popd
+ rm -rf {tmpdir}
'''.format(foobar_dir=foobar_dir, tmpdir=self.tmpdir))
        self.assertEqual(self.stderr.getvalue(), "")
        self.dry_run = False
Example #4
0
    def test_rmtree(self):
        shell.dry_run = False
        path = os.path.join(self.tmpdir, 'foo', 'bar')
        shell.makedirs(path)

        self.assertTrue(os.path.isdir(path))

        shell.rmtree(os.path.join(path))
        self.assertFalse(os.path.exists(os.path.join(path)))
        self.assertTrue(os.path.exists(os.path.join(self.tmpdir, 'foo')))

        self.assertEqual(self.stdout.getvalue(), "")
        self.assertEqual(
            self.stderr.getvalue(), '''\
+ mkdir -p {path}
+ rm -rf {path}
'''.format(path=path))
Example #5
0
    def test_rmtree(self):
        shell.dry_run = False
        path = os.path.join(self.tmpdir, 'foo', 'bar')
        shell.makedirs(path)

        self.assertTrue(os.path.isdir(path))

        shell.rmtree(os.path.join(path))
        self.assertFalse(
            os.path.exists(os.path.join(path)))
        self.assertTrue(
            os.path.exists(os.path.join(self.tmpdir, 'foo')))

        self.assertEqual(self.stdout.getvalue(), "")
        self.assertEqual(self.stderr.getvalue(), '''\
+ mkdir -p {path}
+ rm -rf {path}
'''.format(path=path))
Example #6
0
    def test_pushd(self):
        shell.dry_run = False
        basedir = os.getcwd()

        with shell.pushd(self.tmpdir):
            self.assertEqual(os.getcwd(), self.tmpdir)
        self.assertEqual(os.getcwd(), basedir)

        # pushd inside pushd
        with shell.pushd(self.tmpdir):
            self.assertEqual(os.getcwd(), self.tmpdir)
            shell.makedirs("foo")
            with shell.pushd("foo"):
                self.assertEqual(os.getcwd(), os.path.join(self.tmpdir, "foo"))
            self.assertEqual(os.getcwd(), self.tmpdir)
        self.assertEqual(os.getcwd(), basedir)

        # cd inside pushd
        with shell.pushd(self.tmpdir):
            os.chdir("foo")
            self.assertEqual(os.getcwd(), os.path.join(self.tmpdir, "foo"))
            os.chdir("..")
            self.assertEqual(os.getcwd(), self.tmpdir)
            shell.rmtree("foo")
        self.assertEqual(os.getcwd(), basedir)

        self.assertEqual(self.stdout.getvalue(), "")
        self.assertEqual(
            self.stderr.getvalue(),
            """\
+ pushd {tmpdir}
+ popd
+ pushd {tmpdir}
+ mkdir -p foo
+ pushd foo
+ popd
+ popd
+ pushd {tmpdir}
+ rm -rf foo
+ popd
""".format(
                tmpdir=self.tmpdir
            ),
        )
Example #7
0
    def test_pushd(self):
        shell.dry_run = False
        basedir = os.getcwd()

        with shell.pushd(self.tmpdir):
            self.assertEqual(os.getcwd(), self.tmpdir)
        self.assertEqual(os.getcwd(), basedir)

        # pushd inside pushd
        with shell.pushd(self.tmpdir):
            self.assertEqual(os.getcwd(), self.tmpdir)
            shell.makedirs('foo')
            with shell.pushd('foo'):
                self.assertEqual(os.getcwd(), os.path.join(self.tmpdir, 'foo'))
            self.assertEqual(os.getcwd(), self.tmpdir)
        self.assertEqual(os.getcwd(), basedir)

        # cd inside pushd
        with shell.pushd(self.tmpdir):
            os.chdir('foo')
            self.assertEqual(os.getcwd(), os.path.join(self.tmpdir, 'foo'))
            os.chdir('..')
            self.assertEqual(os.getcwd(), self.tmpdir)
            shell.rmtree('foo')
        self.assertEqual(os.getcwd(), basedir)

        self.assertEqual(self.stdout.getvalue(), "")
        self.assertEqual(
            self.stderr.getvalue(), '''\
+ pushd {tmpdir}
+ popd
+ pushd {tmpdir}
+ mkdir -p foo
+ pushd foo
+ popd
+ popd
+ pushd {tmpdir}
+ rm -rf foo
+ popd
'''.format(tmpdir=self.tmpdir))