<s> from __future__ import with_statement <EOL> import datetime <EOL> import vcs <EOL> from vcs . tests . base import BackendTestMixin <EOL> from vcs . tests . conf import SCM_TESTS <EOL> from vcs . backends . base import BaseChangeset <EOL> from vcs . nodes import ( <EOL> FileNode , AddedFileNodesGenerator , <EOL> ChangedFileNodesGenerator , RemovedFileNodesGenerator <EOL> ) <EOL> from vcs . exceptions import ( <EOL> BranchDoesNotExistError , ChangesetDoesNotExistError , <EOL> RepositoryError <EOL> ) <EOL> from vcs . utils . compat import unittest <EOL> class TestBaseChangeset ( unittest . TestCase ) : <EOL> def test_as_dict ( self ) : <EOL> changeset = BaseChangeset ( ) <EOL> changeset . id = '<STR_LIT>' <EOL> changeset . raw_id = '<STR_LIT>' <EOL> changeset . short_id = '<STR_LIT>' <EOL> changeset . revision = <NUM_LIT> <EOL> changeset . date = datetime . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:30> , <NUM_LIT:1> , <NUM_LIT> ) <EOL> changeset . message = '<STR_LIT>' <EOL> changeset . author = '<STR_LIT>' <EOL> changeset . added = [ FileNode ( '<STR_LIT>' ) , FileNode ( '<STR_LIT>' ) ] <EOL> changeset . changed = [ ] <EOL> changeset . removed = [ ] <EOL> self . assertEqual ( changeset . as_dict ( ) , { <EOL> '<STR_LIT:id>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT:date>' : datetime . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:30> , <NUM_LIT:1> , <NUM_LIT> ) , <EOL> '<STR_LIT:message>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:email>' : '<STR_LIT>' , <EOL> } , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] , <EOL> } ) <EOL> class ChangesetsWithCommitsTestCaseixin ( BackendTestMixin ) : <EOL> recreate_repo_per_test = True <EOL> @ classmethod <EOL> def _get_commits ( cls ) : <EOL> start_date = datetime . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:20> ) <EOL> for x in xrange ( <NUM_LIT:5> ) : <EOL> yield { <EOL> '<STR_LIT:message>' : '<STR_LIT>' % x , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:date>' : start_date + datetime . timedelta ( hours = <NUM_LIT:12> * x ) , <EOL> '<STR_LIT>' : [ <EOL> FileNode ( '<STR_LIT>' % x , content = '<STR_LIT>' % x ) , <EOL> ] , <EOL> } <EOL> def test_new_branch ( self ) : <EOL> self . imc . add ( vcs . nodes . FileNode ( '<STR_LIT>' , <EOL> content = '<STR_LIT>' ) ) <EOL> foobar_tip = self . imc . commit ( <EOL> message = u'<STR_LIT>' , <EOL> author = u'<STR_LIT>' , <EOL> branch = '<STR_LIT>' , <EOL> ) <EOL> self . assertTrue ( '<STR_LIT>' in self . repo . branches ) <EOL> self . assertEqual ( foobar_tip . branch , '<STR_LIT>' ) <EOL> self . assertNotEqual ( * self . repo . branches . values ( ) ) <EOL> def test_new_head_in_default_branch ( self ) : <EOL> tip = self . repo . get_changeset ( ) <EOL> self . imc . add ( vcs . nodes . FileNode ( '<STR_LIT>' , <EOL> content = '<STR_LIT>' ) ) <EOL> foobar_tip = self . imc . commit ( <EOL> message = u'<STR_LIT>' , <EOL> author = u'<STR_LIT>' , <EOL> branch = '<STR_LIT>' , <EOL> parents = [ tip ] , <EOL> ) <EOL> self . imc . change ( vcs . nodes . FileNode ( '<STR_LIT>' , <EOL> content = '<STR_LIT>' ) ) <EOL> newtip = self . imc . commit ( <EOL> message = u'<STR_LIT>' , <EOL> author = u'<STR_LIT>' , <EOL> branch = foobar_tip . branch , <EOL> parents = [ foobar_tip ] , <EOL> ) <EOL> newest_tip = self . imc . commit ( <EOL> message = u'<STR_LIT>' % foobar_tip . raw_id , <EOL> author = u'<STR_LIT>' , <EOL> branch = self . backend_class . DEFAULT_BRANCH_NAME , <EOL> parents = [ newtip , foobar_tip ] , <EOL> ) <EOL> self . assertEqual ( newest_tip . branch , <EOL> self . backend_class . DEFAULT_BRANCH_NAME ) <EOL> def test_get_changesets_respects_branch_name ( self ) : <EOL> tip = self . repo . get_changeset ( ) <EOL> self . imc . add ( vcs . nodes . FileNode ( '<STR_LIT>' , <EOL> content = '<STR_LIT>' ) ) <EOL> doc_changeset = self . imc . commit ( <EOL> message = u'<STR_LIT>' , <EOL> author = u'<STR_LIT>' , <EOL> branch = '<STR_LIT>' , <EOL> ) <EOL> self . imc . add ( vcs . nodes . FileNode ( '<STR_LIT>' , content = '<STR_LIT>' ) ) <EOL> self . imc . commit ( <EOL> message = u'<STR_LIT>' , <EOL> author = u'<STR_LIT>' , <EOL> parents = [ tip ] , <EOL> ) <EOL> default_branch_changesets = self . repo . get_changesets ( <EOL> branch_name = self . repo . DEFAULT_BRANCH_NAME ) <EOL> self . assertNotIn ( doc_changeset , default_branch_changesets ) <EOL> def test_get_changeset_by_branch ( self ) : <EOL> for branch , sha in self . repo . branches . iteritems ( ) : <EOL> self . assertEqual ( sha , self . repo . get_changeset ( branch ) . raw_id ) <EOL> def test_get_changeset_by_tag ( self ) : <EOL> for tag , sha in self . repo . tags . iteritems ( ) : <EOL> self . assertEqual ( sha , self . repo . get_changeset ( tag ) . raw_id ) <EOL> class ChangesetsTestCaseMixin ( BackendTestMixin ) : <EOL> recreate_repo_per_test = False <EOL> @ classmethod <EOL> def _get_commits ( cls ) : <EOL> start_date = datetime . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:20> ) <EOL> for x in xrange ( <NUM_LIT:5> ) : <EOL> yield { <EOL> '<STR_LIT:message>' : u'<STR_LIT>' % x , <EOL> '<STR_LIT>' : u'<STR_LIT>' , <EOL> '<STR_LIT:date>' : start_date + datetime . timedelta ( hours = <NUM_LIT:12> * x ) , <EOL> '<STR_LIT>' : [ <EOL> FileNode ( '<STR_LIT>' % x , content = '<STR_LIT>' % x ) , <EOL> ] , <EOL> } <EOL> def test_simple ( self ) : <EOL> tip = self . repo . get_changeset ( ) <EOL> self . assertEqual ( tip . date , datetime . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:20> ) ) <EOL> def test_get_changesets_is_ordered_by_date ( self ) : <EOL> changesets = list ( self . repo . get_changesets ( ) ) <EOL> ordered_by_date = sorted ( changesets , <EOL> key = lambda cs : cs . date ) <EOL> self . assertItemsEqual ( changesets , ordered_by_date ) <EOL> def test_get_changesets_respects_start ( self ) : <EOL> second_id = self . repo . revisions [ <NUM_LIT:1> ] <EOL> changesets = list ( self . repo . get_changesets ( start = second_id ) ) <EOL> self . assertEqual ( len ( changesets ) , <NUM_LIT:4> ) <EOL> def test_get_changesets_numerical_id_respects_start ( self ) : <EOL> second_id = <NUM_LIT:1> <EOL> changesets = list ( self . repo . get_changesets ( start = second_id ) ) <EOL> self . assertEqual ( len ( changesets ) , <NUM_LIT:4> ) <EOL> def test_get_changesets_includes_start_changeset ( self ) : <EOL> second_id = self . repo . revisions [ <NUM_LIT:1> ] <EOL> changesets = list ( self . repo . get_changesets ( start = second_id ) ) <EOL> self . assertEqual ( changesets [ <NUM_LIT:0> ] . raw_id , second_id ) <EOL> def test_get_changesets_respects_end ( self ) : <EOL> second_id = self . repo . revisions [ <NUM_LIT:1> ] <EOL> changesets = list ( self . repo . get_changesets ( end = second_id ) ) <EOL> self . assertEqual ( changesets [ - <NUM_LIT:1> ] . raw_id , second_id ) <EOL> self . assertEqual ( len ( changesets ) , <NUM_LIT:2> ) <EOL> def test_get_changesets_numerical_id_respects_end ( self ) : <EOL> second_id = <NUM_LIT:1> <EOL> changesets = list ( self . repo . get_changesets ( end = second_id ) ) <EOL> self . assertEqual ( changesets . index ( changesets [ - <NUM_LIT:1> ] ) , second_id ) <EOL> self . assertEqual ( len ( changesets ) , <NUM_LIT:2> ) <EOL> def test_get_changesets_respects_both_start_and_end ( self ) : <EOL> second_id = self . repo . revisions [ <NUM_LIT:1> ] <EOL> third_id = self . repo . revisions [ <NUM_LIT:2> ] <EOL> changesets = list ( self . repo . get_changesets ( start = second_id , <EOL> end = third_id ) ) <EOL> self . assertEqual ( len ( changesets ) , <NUM_LIT:2> ) <EOL> def test_get_changesets_numerical_id_respects_both_start_and_end ( self ) : <EOL> changesets = list ( self . repo . get_changesets ( start = <NUM_LIT:2> , end = <NUM_LIT:3> ) ) <EOL> self . assertEqual ( len ( changesets ) , <NUM_LIT:2> ) <EOL> def test_get_changesets_includes_end_changeset ( self ) : <EOL> second_id = self . repo . revisions [ <NUM_LIT:1> ] <EOL> changesets = list ( self . repo . get_changesets ( end = second_id ) ) <EOL> self . assertEqual ( changesets [ - <NUM_LIT:1> ] . raw_id , second_id ) <EOL> def test_get_changesets_respects_start_date ( self ) : <EOL> start_date = datetime . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:2> ) <EOL> for cs in self . repo . get_changesets ( start_date = start_date ) : <EOL> self . assertGreaterEqual ( cs . date , start_date ) <EOL> def test_get_changesets_respects_end_date ( self ) : <EOL> end_date = datetime . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:2> ) <EOL> for cs in self . repo . get_changesets ( end_date = end_date ) : <EOL> self . assertLessEqual ( cs . date , end_date ) <EOL> def test_get_changesets_respects_start_date_and_end_date ( self ) : <EOL> start_date = datetime . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> end_date = datetime . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:3> ) <EOL> for cs in self . repo . get_changesets ( start_date = start_date , <EOL> end_date = end_date ) : <EOL> self . assertGreaterEqual ( cs . date , start_date ) <EOL> self . assertLessEqual ( cs . date , end_date ) <EOL> def test_get_changesets_respects_start_date_and_end_date_and_branch_name ( self ) : <EOL> start_date = datetime . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> end_date = datetime . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:3> ) <EOL> for cs in self . repo . get_changesets ( start_date = start_date , <EOL> end_date = end_date , <EOL> branch_name = self . repo . DEFAULT_BRANCH_NAME ) : <EOL> self . assertGreaterEqual ( cs . date , start_date ) <EOL> self . assertLessEqual ( cs . date , end_date ) <EOL> def test_get_changesets_respects_reverse ( self ) : <EOL> changesets_id_list = [ cs . raw_id for cs in <EOL> self . repo . get_changesets ( reverse = True ) ] <EOL> self . assertItemsEqual ( changesets_id_list , reversed ( self . repo . revisions ) ) <EOL> def test_get_filenodes_generator ( self ) : <EOL> tip = self . repo . get_changeset ( ) <EOL> filepaths = [ node . path for node in tip . get_filenodes_generator ( ) ] <EOL> self . assertItemsEqual ( filepaths , [ '<STR_LIT>' % x for x in xrange ( <NUM_LIT:5> ) ] ) <EOL> def test_size ( self ) : <EOL> tip = self . repo . get_changeset ( ) <EOL> size = <NUM_LIT:5> * len ( '<STR_LIT>' ) <EOL> self . assertEqual ( tip . size , size ) <EOL> def test_author ( self ) : <EOL> tip = self . repo . get_changeset ( ) <EOL> self . assertEqual ( tip . author , u'<STR_LIT>' ) <EOL> def test_author_name ( self ) : <EOL> tip = self . repo . get_changeset ( ) <EOL> self . assertEqual ( tip . author_name , u'<STR_LIT>' ) <EOL> def test_author_email ( self ) : <EOL> tip = self . repo . get_changeset ( ) <EOL> self . assertEqual ( tip . author_email , u'<STR_LIT>' ) <EOL> def test_get_changesets_raise_changesetdoesnotexist_for_wrong_start ( self ) : <EOL> with self . assertRaises ( ChangesetDoesNotExistError ) : <EOL> list ( self . repo . get_changesets ( start = '<STR_LIT>' ) ) <EOL> def test_get_changesets_raise_changesetdoesnotexist_for_wrong_end ( self ) : <EOL> with self . assertRaises ( ChangesetDoesNotExistError ) : <EOL> list ( self . repo . get_changesets ( end = '<STR_LIT>' ) ) <EOL> def test_get_changesets_raise_branchdoesnotexist_for_wrong_branch_name ( self ) : <EOL> with self . assertRaises ( BranchDoesNotExistError ) : <EOL> list ( self . repo . get_changesets ( branch_name = '<STR_LIT>' ) ) <EOL> def test_get_changesets_raise_repositoryerror_for_wrong_start_end ( self ) : <EOL> start = self . repo . revisions [ - <NUM_LIT:1> ] <EOL> end = self . repo . revisions [ <NUM_LIT:0> ] <EOL> with self . assertRaises ( RepositoryError ) : <EOL> list ( self . repo . get_changesets ( start = start , end = end ) ) <EOL> def test_get_changesets_numerical_id_reversed ( self ) : <EOL> with self . assertRaises ( RepositoryError ) : <EOL> [ x for x in self . repo . get_changesets ( start = <NUM_LIT:3> , end = <NUM_LIT:2> ) ] <EOL> def test_get_changesets_numerical_id_respects_both_start_and_end_last ( self ) : <EOL> with self . assertRaises ( RepositoryError ) : <EOL> last = len ( self . repo . revisions ) <EOL> list ( self . repo . get_changesets ( start = last - <NUM_LIT:1> , end = last - <NUM_LIT:2> ) ) <EOL> def test_get_changesets_numerical_id_last_zero_error ( self ) : <EOL> with self . assertRaises ( RepositoryError ) : <EOL> last = len ( self . repo . revisions ) <EOL> list ( self . repo . get_changesets ( start = last - <NUM_LIT:1> , end = <NUM_LIT:0> ) ) <EOL> class ChangesetsChangesTestCaseMixin ( BackendTestMixin ) : <EOL> recreate_repo_per_test = False <EOL> @ classmethod <EOL> def _get_commits ( cls ) : <EOL> return [ <EOL> { <EOL> '<STR_LIT:message>' : u'<STR_LIT>' , <EOL> '<STR_LIT>' : u'<STR_LIT>' , <EOL> '<STR_LIT:date>' : datetime . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:20> ) , <EOL> '<STR_LIT>' : [ <EOL> FileNode ( '<STR_LIT>' , content = '<STR_LIT:foo>' ) , <EOL> FileNode ( '<STR_LIT>' , content = '<STR_LIT:foo>' ) , <EOL> FileNode ( '<STR_LIT>' , content = '<STR_LIT:foo>' ) , <EOL> ] , <EOL> } , <EOL> { <EOL> '<STR_LIT:message>' : u'<STR_LIT>' , <EOL> '<STR_LIT>' : u'<STR_LIT>' , <EOL> '<STR_LIT:date>' : datetime . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT> ) , <EOL> '<STR_LIT>' : [ FileNode ( '<STR_LIT>' , content = '<STR_LIT>' ) ] , <EOL> '<STR_LIT>' : [ <EOL> FileNode ( '<STR_LIT>' , content = '<STR_LIT>' ) , <EOL> FileNode ( '<STR_LIT>' , content = '<STR_LIT>' ) , <EOL> ] , <EOL> '<STR_LIT>' : [ FileNode ( '<STR_LIT>' ) ] , <EOL> } , <EOL> ] <EOL> def test_initial_commit ( self ) : <EOL> changeset = self . repo . get_changeset ( <NUM_LIT:0> ) <EOL> self . assertItemsEqual ( changeset . added , [ <EOL> changeset . get_node ( '<STR_LIT>' ) , <EOL> changeset . get_node ( '<STR_LIT>' ) , <EOL> changeset . get_node ( '<STR_LIT>' ) , <EOL> ] ) <EOL> self . assertItemsEqual ( changeset . changed , [ ] ) <EOL> self . assertItemsEqual ( changeset . removed , [ ] ) <EOL> def test_head_added ( self ) : <EOL> changeset = self . repo . get_changeset ( ) <EOL> self . assertTrue ( isinstance ( changeset . added , AddedFileNodesGenerator ) ) <EOL> self . assertItemsEqual ( changeset . added , [ <EOL> changeset . get_node ( '<STR_LIT>' ) , <EOL> ] ) <EOL> self . assertTrue ( isinstance ( changeset . changed , ChangedFileNodesGenerator ) ) <EOL> self . assertItemsEqual ( changeset . changed , [ <EOL> changeset . get_node ( '<STR_LIT>' ) , <EOL> changeset . get_node ( '<STR_LIT>' ) , <EOL> ] ) <EOL> self . assertTrue ( isinstance ( changeset . removed , RemovedFileNodesGenerator ) ) <EOL> self . assertEqual ( len ( changeset . removed ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( list ( changeset . removed ) [ <NUM_LIT:0> ] . path , '<STR_LIT>' ) <EOL> for alias in SCM_TESTS : <EOL> attrs = { <EOL> '<STR_LIT>' : alias , <EOL> } <EOL> cls_name = '<STR_LIT>' . join ( ( '<STR_LIT>' % alias ) . title ( ) . split ( ) ) <EOL> bases = ( ChangesetsWithCommitsTestCaseixin , unittest . TestCase ) <EOL> globals ( ) [ cls_name ] = type ( cls_name , bases , attrs ) <EOL> cls_name = '<STR_LIT>' . join ( ( '<STR_LIT>' % alias ) . title ( ) . split ( ) ) <EOL> bases = ( ChangesetsTestCaseMixin , unittest . TestCase ) <EOL> globals ( ) [ cls_name ] = type ( cls_name , bases , attrs ) <EOL> cls_name = '<STR_LIT>' . join ( ( '<STR_LIT>' % alias ) . title ( ) . split ( ) ) <EOL> bases = ( ChangesetsChangesTestCaseMixin , unittest . TestCase ) <EOL> globals ( ) [ cls_name ] = type ( cls_name , bases , attrs ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
