コード例 #1
0
ファイル: test_template.py プロジェクト: gregatsoon/Facio
 def should_detect_git_repo(self, mock_tmp_dir, mock_clone, mock_tempfile,
                            mock_stdout):
     t = Template(self.config)
     assert not t.vcs_cls
     self.config.template = '[email protected]:repo.git'
     t = Template(self.config)
     self.assertEquals(t.vcs_cls.__class__.__name__, 'Git')
コード例 #2
0
ファイル: test_template.py プロジェクト: gregatsoon/Facio
    def should_clone_git_repo(self, mock_working_dir):

        # Create a fake temp repo w/ commit
        git_dir = tempfile.mkdtemp(prefix='git')
        git_repo = Repo.init(git_dir)
        try:
            f = open(os.path.join(git_dir, 'foo.txt'), 'w')
            f.write('blah')
        except IOError:
            assert False
        finally:
            f.close()
        cwd = os.getcwd()
        os.chdir(git_dir)
        git_repo.index.add(['foo.txt'])
        git_repo.index.commit("Added foo.txt")
        os.chdir(cwd)

        # Fake Template Path
        mock_working_dir.return_value = tempfile.gettempdir()

        # Now attempt to clone but patch for Exception throw
        self.config.template = 'git+' + git_dir
        t = Template(self.config)
        t.copy_template()

        # Clean up
        rmtree(t.project_root)

        self.assertFalse(os.path.isdir(t.config.template))
        self.assertFalse(self.config.cli_opts.error.called)
コード例 #3
0
    def run(self):
        """ Run the Facio processes. """

        interface = CommandLineInterface()
        interface.start()

        config = ConfigurationFile()
        parsed = config.read()

        settings = Settings(interface, parsed)
        state.update_context_variables(settings.get_variables())

        template = Template(settings.get_template_path())
        template.update_copy_ignore_globs(settings.copy_ignore_globs())
        template.update_render_ignore_globs(settings.render_ignore_globs())
        template.copy()

        pipeline = Hook()
        pipeline.load(os.path.join(state.get_project_root(), HOOKS_FILE_NAME))

        if pipeline.has_before():
            pipeline.run_before()

        template.rename()
        template.render()

        if pipeline.has_after():
            pipeline.run_after()

        self.success('Done')
コード例 #4
0
ファイル: test_template.py プロジェクト: gregatsoon/Facio
 def should_copy_directory_tree_if_is_dir(self, mock_working_dir):
     mock_working_dir.return_value = tempfile.gettempdir()
     t = Template(self.config)
     t.exclude_dirs.append('.exclude_this')
     t.copy_template()
     self.assertTrue(
         os.path.isdir(os.path.join(t.project_root, 'should_copy_this')))
     rmtree(t.project_root)
コード例 #5
0
ファイル: test_template.py プロジェクト: gregatsoon/Facio
    def ensure_custom_variables_added_to_placeholders(self):
        self.config.variables = 'foo=bar,baz=1'
        t = Template(self.config)

        self.assertTrue('foo' in t.place_holders)
        self.assertEquals(t.place_holders['foo'], 'bar')
        self.assertTrue('baz' in t.place_holders)
        self.assertEquals(t.place_holders['baz'], '1')
コード例 #6
0
ファイル: test_template.py プロジェクト: gregatsoon/Facio
 def ensure_excluded_dirs_are_not_copied(self, mock_working_dir):
     mock_working_dir.return_value = tempfile.gettempdir()
     t = Template(self.config)
     t.exclude_dirs.append('.exclude_this')
     t.copy_template()
     self.assertFalse(
         os.path.isdir(os.path.join(t.project_root, '.exclude_this')))
     rmtree(t.project_root)
コード例 #7
0
ファイル: test_template.py プロジェクト: gregatsoon/Facio
 def ensure_error_on_clone_exception(self, mock_repo_init):
     self.config.template = 'git+this/wont/work'
     try:
         Template(self.config)
     except:
         assert True
     else:
         assert False
コード例 #8
0
ファイル: test_template.py プロジェクト: gregatsoon/Facio
 def should_rename_files_in_placeholders(self, mock_working_dir):
     mock_working_dir.return_value = tempfile.gettempdir()
     t = Template(self.config)
     t.copy_template()
     self.assertTrue(
         os.path.isfile(
             os.path.join(t.project_root, '__NOT_IN_PLACEHOLDERS__',
                          '%s.txt' % self.config.project_name)))
     rmtree(t.project_root)
コード例 #9
0
ファイル: test_template.py プロジェクト: gregatsoon/Facio
 def ensure_directory_not_renamed_if_not_in_placeholders(
         self, mock_working_dir):
     mock_working_dir.return_value = tempfile.gettempdir()
     t = Template(self.config)
     t.copy_template()
     self.assertTrue(
         os.path.isdir(
             os.path.join(t.project_root, '__NOT_IN_PLACEHOLDERS__')))
     rmtree(t.project_root)
コード例 #10
0
ファイル: test_template.py プロジェクト: areski/Facio
 def test_copy_template_failes_if_dir_does_not_exist(
         self, mock_working_dir, mock_error, mock_isdir):
     mock_working_dir.return_value = tempfile.gettempdir()
     tmp_dir = tempfile.mkdtemp(suffix=self.config.project_name, prefix='')
     tmp_dir_name = list(os.path.split(tmp_dir))[-1:][0]
     self.config.project_name = tmp_dir_name
     t = Template(self.config)
     t.copy_template()
     self.config._error.assert_called_with(
         'Unable to copy template, directory does not exist')
コード例 #11
0
ファイル: test_template.py プロジェクト: areski/Facio
    def test_dir_cannot_be_created_if_already_exists(self, mock_working_dir,
                                                     mock_error, mock_isdir):
        mock_working_dir.return_value = tempfile.gettempdir()
        tmp_dir = tempfile.mkdtemp(suffix=self.config.project_name, prefix='')
        tmp_dir_name = list(os.path.split(tmp_dir))[-1:][0]
        self.config.project_name = tmp_dir_name
        t = Template(self.config)
        t.copy_template()
        rmtree(tmp_dir)

        self.config._error.assert_called_with('%s already exists' % (tmp_dir))
コード例 #12
0
ファイル: test_template.py プロジェクト: gregatsoon/Facio
    def ensure_exception_if_directory_creation_fails(self, mock_os_mkdir):
        try:
            t = Template(self.config)
            t.copy_template()
        except Exception:
            assert True
        else:
            assert False

        self.config.cli_opts.error.assert_called_with(
            'Error creating project directory')
        mock_os_mkdir.assert_called_with(
            os.path.join(t.working_dir, self.config.project_name))
コード例 #13
0
ファイル: test_template.py プロジェクト: areski/Facio
    def test_exception_if_directory_creation_fails(self, mock_working_dir,
                                                   mock_error, mock_os_mkdir):
        mock_working_dir.return_value = tempfile.gettempdir()
        tmp_dir = tempfile.mkdtemp(suffix=self.config.project_name, prefix='')
        tmp_dir_name = list(os.path.split(tmp_dir))[-1:][0]
        self.config.project_name = tmp_dir_name
        t = Template(self.config)
        t.copy_template()

        self.config._error.assert_called_with(
            'Error creating project directory')
        mock_os_mkdir.assert_called_with(
            os.path.join(t.working_dir, self.config.project_name))
コード例 #14
0
ファイル: test_template.py プロジェクト: gregatsoon/Facio
 def ensure_copy_template_failes_if_dir_does_not_exist(
         self, mock_working_dir, mock_isdir):
     mock_working_dir.return_value = tempfile.gettempdir()
     tmp_dir = tempfile.mkdtemp(suffix=self.config.project_name, prefix='')
     tmp_dir_name = list(os.path.split(tmp_dir))[-1:][0]
     self.config.project_name = tmp_dir_name
     try:
         t = Template(self.config)
         t.copy_template()
     except:
         self.config.cli_opts.error.assert_called_with(
             'Unable to copy template, directory does not exist')
         assert True
     else:
         assert False
コード例 #15
0
ファイル: test_template.py プロジェクト: gregatsoon/Facio
    def ensure_dir_cannot_be_created_if_already_exists(self, mock_working_dir):
        mock_working_dir.return_value = tempfile.gettempdir()
        tmp_dir = tempfile.mkdtemp(suffix=self.config.project_name, prefix='')
        tmp_dir_name = list(os.path.split(tmp_dir))[-1:][0]
        self.config.project_name = tmp_dir_name
        try:
            t = Template(self.config)
            t.copy_template()
            rmtree(tmp_dir)
        except Exception:
            assert True
        else:
            assert False

        self.config.cli_opts.error.assert_called_with('%s already exists' %
                                                      (tmp_dir))
コード例 #16
0
ファイル: test_template.py プロジェクト: areski/Facio
    def test_clone_git_repo(self, mock_working_dir):

        # Create a fake temp repo w/ commit
        git_dir = tempfile.mkdtemp(prefix='git')
        git.init(git_dir)

        try:
            f = open(os.path.join(git_dir, 'foo.txt'), 'w')
            f.write('blah')
        except IOError:
            assert False
        finally:
            f.close()
        cwd = os.getcwd()
        os.chdir(git_dir)
        git.add('foo.txt')
        if os.environ.get('TRAVIS_CI') == 'true':
            git.config('--global', 'user.email',
                       '"*****@*****.**"')
            git.config('--global', 'user.name', '"Testing on Travis CI"')
        git.commit('-m "Added foo.txt"')
        os.chdir(cwd)

        # Fake Template Path
        mock_working_dir.return_value = tempfile.gettempdir()

        # Now attempt to clone but patch for Exception throw
        self.config.template = 'git+' + git_dir
        self.config._tpl = git_dir
        t = Template(self.config)
        t.copy_template()

        # Clean up
        rmtree(t.project_root)

        self.assertFalse(os.path.isdir(t.config.template))
        self.assertFalse(self.config.cli_opts.error.called)
コード例 #17
0
ファイル: test_template.py プロジェクト: gregatsoon/Facio
    def should_handle_malformed_variables_gracefully(self):
        self.config.variables = 'this,is.wrong'
        t = Template(self.config)

        self.assertEquals(len(t.place_holders), 3)