<s> from __future__ import unicode_literals <EOL> import logging <EOL> import os <EOL> import os . path <EOL> from mock import patch , call <EOL> from sprinter . testtools import FormulaTest <EOL> import sprinter . lib as lib <EOL> from sprinter . formula . git import CURRENT_REMOTE , CURRENT_BRANCH , CLONE_REPO , CHECKOUT_BRANCH , FETCH_BRANCH , MERGE_BRANCH , UPDATE_ORIGIN <EOL> vals = { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> source_config = """<STR_LIT>""" % vals <EOL> target_config = """<STR_LIT>""" % vals <EOL> class TestGitFormula ( FormulaTest ) : <EOL> """<STR_LIT>""" <EOL> def setup ( self ) : <EOL> super ( TestGitFormula , self ) . setup ( source_config = source_config , <EOL> target_config = target_config ) <EOL> self . curdir = os . path . abspath ( os . curdir ) <EOL> def teardown ( self ) : <EOL> os . chdir ( self . curdir ) <EOL> @ patch . object ( lib , '<STR_LIT>' ) <EOL> def test_simple_example ( self , call_mock ) : <EOL> """<STR_LIT>""" <EOL> install_directory = self . directory . install_directory ( '<STR_LIT>' ) <EOL> call_mock . return_value = ( <NUM_LIT:0> , '<STR_LIT>' ) <EOL> self . environment . run_feature ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> call_mock . assert_has_calls ( [ <EOL> call ( CLONE_REPO . format ( <EOL> repo = vals [ '<STR_LIT>' ] , <EOL> dir = install_directory <EOL> ) , output_log_level = logging . DEBUG ) <EOL> ] ) <EOL> @ patch . object ( lib , '<STR_LIT>' ) <EOL> def test_update_different_branches ( self , call_mock ) : <EOL> """<STR_LIT>""" <EOL> install_directory = self . directory . install_directory ( '<STR_LIT>' ) <EOL> os . makedirs ( install_directory ) <EOL> call_count = <NUM_LIT:0> <EOL> return_values = { <EOL> CURRENT_REMOTE . format ( dir = install_directory ) : <EOL> '<STR_LIT>' , <EOL> CURRENT_BRANCH . format ( dir = install_directory ) : <EOL> '<STR_LIT>' <EOL> } <EOL> call_mock . side_effect = lambda cmd , ** kw : ( <NUM_LIT:0> , return_values [ cmd ] if cmd in return_values else '<STR_LIT>' ) <EOL> self . environment . run_feature ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> call_mock . assert_any_call ( <EOL> FETCH_BRANCH . format ( dir = install_directory , branch = '<STR_LIT>' ) , <EOL> output_log_level = logging . DEBUG <EOL> ) <EOL> call_mock . assert_any_call ( <EOL> CHECKOUT_BRANCH . format ( dir = install_directory , branch = '<STR_LIT>' ) , <EOL> output_log_level = logging . DEBUG <EOL> ) <EOL> @ patch . object ( lib , '<STR_LIT>' ) <EOL> def test_update_no_directory ( self , call_mock ) : <EOL> """<STR_LIT>""" <EOL> call_mock . return_value = ( <NUM_LIT:0> , '<STR_LIT>' ) <EOL> self . environment . run_feature ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> call_mock . assert_any_call ( <EOL> CLONE_REPO . format ( <EOL> repo = vals [ '<STR_LIT>' ] , <EOL> dir = self . directory . install_directory ( '<STR_LIT>' ) ) , <EOL> output_log_level = logging . DEBUG ) </s>
