Пример #1
0
    def test_makefile(self):
        template = "KEY=%(key)s"
        params = {'key': 'value'}

        orig_stdout = sys.stdout
        temp_out_file = cStringIO.StringIO()
        sys.stdout = temp_out_file
        makefile(template, self.temp_dir, 'test.txt', **params)
        sys.stdout = orig_stdout
        path = os.path.join(self.temp_dir, 'test.txt')
        self.assertEqual('Wrote file %s\n' % path, temp_out_file.getvalue())

        self.assertEqual('KEY=value', open(path).read())
    def test_makefile(self):
        import os
        from zope.mkzeoinstance import makefile
        template = "KEY=%(key)s"
        params = {'key': 'value'}
        temp_dir = self._makeTempDir()
        path = os.path.join(temp_dir, 'test.txt')

        with TempStdout() as temp_out_file:
            makefile(template, temp_dir, 'test.txt', **params)
            self.assertEqual('Wrote file %s\n' % path,
                            temp_out_file.getvalue())

        with open(path) as f:
            self.assertEqual('KEY=value', f.read())
Пример #3
0
    def test_makefile(self):
        template = "KEY=%(key)s"
        params = {'key': 'value'}

        orig_stdout = sys.stdout
        temp_out_file = cStringIO.StringIO()
        sys.stdout = temp_out_file
        makefile(template, self.temp_dir, 'test.txt', **params)
        sys.stdout = orig_stdout
        path = os.path.join(self.temp_dir, 'test.txt')
        self.assertEqual('Wrote file %s\n'%path,
                         temp_out_file.getvalue())

        self.assertEqual('KEY=value',
                         open(path).read())
Пример #4
0
    def test_makefile(self):
        import os
        from zope.mkzeoinstance import makefile
        template = "KEY=%(key)s"
        params = {'key': 'value'}
        temp_dir = self._makeTempDir()
        path = os.path.join(temp_dir, 'test.txt')

        with TempStdout() as temp_out_file:
            makefile(template, temp_dir, 'test.txt', **params)
            self.assertEqual('Wrote file %s\n' % path,
                            temp_out_file.getvalue())

        with open(path) as f:
            self.assertEqual('KEY=value', f.read())
    def test_makefile_existing_different_content(self):
        import os
        from zope.mkzeoinstance import makefile
        template = "KEY=%(key)s"
        params = {'key': 'value'}
        temp_dir = self._makeTempDir()
        path = os.path.join(temp_dir, 'test.txt')

        with open(path, 'w') as f:
            f.write('NOT THE SAME CONTENT')

        with TempStdout() as temp_out_file:
            makefile(template, temp_dir, 'test.txt', **params)

        self.assertEqual('Warning: not overwriting existing file %s\n' % path,
                          temp_out_file.getvalue())

        with open(path) as f:
            self.assertEqual('NOT THE SAME CONTENT', f.read())
Пример #6
0
    def test_makefile_existing_different_content(self):
        import os
        from zope.mkzeoinstance import makefile
        template = "KEY=%(key)s"
        params = {'key': 'value'}
        temp_dir = self._makeTempDir()
        path = os.path.join(temp_dir, 'test.txt')

        with open(path, 'w') as f:
            f.write('NOT THE SAME CONTENT')

        with TempStdout() as temp_out_file:
            makefile(template, temp_dir, 'test.txt', **params)

        self.assertEqual('Warning: not overwriting existing file %s\n' % path,
                          temp_out_file.getvalue())

        with open(path) as f:
            self.assertEqual('NOT THE SAME CONTENT', f.read())