# Path: templar/api/config.py
# class ConfigBuilderError(TemplarError):
#     pass
# 
# Path: templar/cli/templar.py
# LOGGING_FORMAT = '%(levelname)s %(filename)s:%(lineno)d> %(message)s'
# def flags(args=None):
# def run(args):
# def main():


from templar.api.config import ConfigBuilderError
from templar.cli import templar
import io
import mock
import os.path
import shutil
import unittest
                '-d', destination_file,
                '--print',
                '--debug',
            ]))
        # Using --print should prevent writing to the destination.
        self.assertFalse(os.path.isfile(destination_file))
        # There should be trailing newline because the print function adds a
        # newline at the end.
        self.assertEqual('<p>Content in my block.</p>\n', mock_stdout.getvalue())

    def testPrintErrorIfDebugFlagNotUsed(self):
        destination_file = os.path.join(STAGING_DIR, 'destination.html')
        with self.assertRaises(SystemExit) as cm:
            with mock.patch('sys.stderr', new_callable=io.StringIO) as mock_stdout:
                templar.run(templar.flags([
                    # Missing both source and template causes an error.
                    '-c', os.path.join(TEST_DATA, 'config.py'),
                ]))
        self.assertFalse(os.path.isfile(destination_file))
        self.assertEqual(
                'PublishError: When publishing, source and template cannot both be omitted.\n',
                mock_stdout.getvalue())
        self.assertNotEqual(cm.exception.code, 0)


    def testCreateDestinationNonExistentDirectory(self):
        # The directiory STAGING_DIR/dir does not exist beforehand.
        self.assertFalse(os.path.isdir(os.path.join(STAGING_DIR, 'dir')))

        destination_file = os.path.join(STAGING_DIR, 'dir', 'destination.html')

# Path: templar/api/config.py
# class ConfigBuilderError(TemplarError):
#     pass
# 
# Path: templar/cli/templar.py
# LOGGING_FORMAT = '%(levelname)s %(filename)s:%(lineno)d> %(message)s'
# def flags(args=None):
# def run(args):
# def main():


# Path: tests/cli/templar_test.py
from templar.api.config import ConfigBuilderError
from templar.cli import templar
import io
import mock
import os.path
import shutil
import unittest

                '-d', destination_file,
                '--print',
                '--debug',
            ]))
        # Using --print should prevent writing to the destination.
        self.assertFalse(os.path.isfile(destination_file))
        # There should be trailing newline because the print function adds a
        # newline at the end.
        self.assertEqual('<p>Content in my block.</p>\n', mock_stdout.getvalue())

    def testPrintErrorIfDebugFlagNotUsed(self):
        destination_file = os.path.join(STAGING_DIR, 'destination.html')
        with self.assertRaises(SystemExit) as cm:
            with mock.patch('sys.stderr', new_callable=io.StringIO) as mock_stdout:
                templar.run(templar.flags([
                    # Missing both source and template causes an error.
                    '-c', os.path.join(TEST_DATA, 'config.py'),
                ]))
        self.assertFalse(os.path.isfile(destination_file))
        self.assertEqual(
                'PublishError: When publishing, source and template cannot both be omitted.\n',
                mock_stdout.getvalue())
        self.assertNotEqual(cm.exception.code, 0)


    def testCreateDestinationNonExistentDirectory(self):
        # The directiory STAGING_DIR/dir does not exist beforehand.
        self.assertFalse(os.path.isdir(os.path.join(STAGING_DIR, 'dir')))

        destination_file = os.path.join(STAGING_DIR, 'dir', 'destination.html')

        templar.run(templar.flags([