# Path: sprinter/testtools.py
# class FormulaTest(object):
# 
#     def setup(self, **kw):
#         self.environment, self.temp_directory = create_mock_environment(**kw)
#         # adding some extra mocking
#         self.directory = self.environment.directory
#         self.environment.instantiate_features()
# 
#     def tearDown(self):
#         shutil.rmtree(self.temp_directory)
# 
# Path: sprinter/formula/git.py
# CURRENT_REMOTE = "git -C {dir} config --get remote.origin.url"
# 
# CURRENT_BRANCH = "git -C {dir} rev-parse --abbrev-ref HEAD"
# 
# CLONE_REPO = "git clone {repo} {dir}"
# 
# CHECKOUT_BRANCH = "git -C {dir} checkout {branch}"
# 
# FETCH_BRANCH = "git -C {dir} fetch origin {branch}"
# 
# MERGE_BRANCH = "git -C {dir} merge --ff-only origin/{branch}"
# 
# UPDATE_ORIGIN = "git -C {dir} remote set-url origin {repo}"


import logging
import os
import os.path
import sprinter.lib as lib
from mock import patch, call
from sprinter.testtools import FormulaTest
from sprinter.formula.git import CURRENT_REMOTE, CURRENT_BRANCH, CLONE_REPO, CHECKOUT_BRANCH, FETCH_BRANCH, MERGE_BRANCH, UPDATE_ORIGIN

    @patch.object(lib, 'call')
    def test_update_different_branches(self, call_mock):
        """ The git formula should call checkout if target branch is not the current branch """
        install_directory = self.directory.install_directory('update')
        os.makedirs(install_directory)
        call_count = 0
        return_values = {
            CURRENT_REMOTE.format(dir=install_directory):
                'git://github.com/toumorokoshi/sprinter.git',
            CURRENT_BRANCH.format(dir=install_directory):
                'master'
        }
        call_mock.side_effect = lambda cmd, **kw: (0, return_values[cmd] if cmd in return_values else '')
        self.environment.run_feature('update', 'sync')
        call_mock.assert_any_call(
            FETCH_BRANCH.format(dir=install_directory, branch='develop'),
            output_log_level=logging.DEBUG
        )
        call_mock.assert_any_call(
            CHECKOUT_BRANCH.format(dir=install_directory, branch='develop'),
            output_log_level=logging.DEBUG
        )

    @patch.object(lib, 'call')
    def test_update_no_directory(self, call_mock):
        """ The git formula should re-clone a repo if the repo directory doesn't exist """
        call_mock.return_value = (0, 'git://github.com/toumorokoshi/sprinter.git')
        self.environment.run_feature('update', 'sync')
        call_mock.assert_any_call(

# Path: sprinter/testtools.py
# class FormulaTest(object):
# 
#     def setup(self, **kw):
#         self.environment, self.temp_directory = create_mock_environment(**kw)
#         # adding some extra mocking
#         self.directory = self.environment.directory
#         self.environment.instantiate_features()
# 
#     def tearDown(self):
#         shutil.rmtree(self.temp_directory)
# 
# Path: sprinter/formula/git.py
# CURRENT_REMOTE = "git -C {dir} config --get remote.origin.url"
# 
# CURRENT_BRANCH = "git -C {dir} rev-parse --abbrev-ref HEAD"
# 
# CLONE_REPO = "git clone {repo} {dir}"
# 
# CHECKOUT_BRANCH = "git -C {dir} checkout {branch}"
# 
# FETCH_BRANCH = "git -C {dir} fetch origin {branch}"
# 
# MERGE_BRANCH = "git -C {dir} merge --ff-only origin/{branch}"
# 
# UPDATE_ORIGIN = "git -C {dir} remote set-url origin {repo}"


# Path: sprinter/formula/tests/test_git.py
import logging
import os
import os.path
import sprinter.lib as lib
from mock import patch, call
from sprinter.testtools import FormulaTest
from sprinter.formula.git import CURRENT_REMOTE, CURRENT_BRANCH, CLONE_REPO, CHECKOUT_BRANCH, FETCH_BRANCH, MERGE_BRANCH, UPDATE_ORIGIN


    @patch.object(lib, 'call')
    def test_update_different_branches(self, call_mock):
        """ The git formula should call checkout if target branch is not the current branch """
        install_directory = self.directory.install_directory('update')
        os.makedirs(install_directory)
        call_count = 0
        return_values = {
            CURRENT_REMOTE.format(dir=install_directory):
                'git://github.com/toumorokoshi/sprinter.git',
            CURRENT_BRANCH.format(dir=install_directory):
                'master'
        }
        call_mock.side_effect = lambda cmd, **kw: (0, return_values[cmd] if cmd in return_values else '')
        self.environment.run_feature('update', 'sync')
        call_mock.assert_any_call(
            FETCH_BRANCH.format(dir=install_directory, branch='develop'),
            output_log_level=logging.DEBUG
        )
        call_mock.assert_any_call(
            CHECKOUT_BRANCH.format(dir=install_directory, branch='develop'),
            output_log_level=logging.DEBUG
        )

    @patch.object(lib, 'call')
    def test_update_no_directory(self, call_mock):
        """ The git formula should re-clone a repo if the repo directory doesn't exist """
        call_mock.return_value = (0, 'git://github.com/toumorokoshi/sprinter.git')
        self.environment.run_feature('update', 'sync')
        call_mock.assert_any_call(

            CLONE_REPO.format(