<s> import qisys . qixml <EOL> import qisys . worktree <EOL> import qisrc . worktree <EOL> from qisrc . git_config import Remote <EOL> import pytest <EOL> def test_read_git_configs ( tmpdir , test_git ) : <EOL> tmpdir . mkdir ( "<STR_LIT:foo>" ) <EOL> tmpdir . mkdir ( "<STR_LIT:bar>" ) <EOL> wt = qisys . worktree . WorkTree ( tmpdir . strpath ) <EOL> foo_proj = wt . add_project ( "<STR_LIT:foo>" ) <EOL> bar_proj = wt . add_project ( "<STR_LIT:bar>" ) <EOL> git = test_git ( foo_proj . path ) <EOL> git . initialize ( ) <EOL> git = test_git ( bar_proj . path ) <EOL> git . initialize ( branch = "<STR_LIT>" ) <EOL> tmpdir . join ( "<STR_LIT>" ) . join ( "<STR_LIT>" ) . write ( """<STR_LIT>""" ) <EOL> git_wt = qisrc . worktree . GitWorkTree ( wt ) <EOL> git_projects = git_wt . git_projects <EOL> assert len ( git_projects ) == <NUM_LIT:2> <EOL> foo = git_wt . get_git_project ( "<STR_LIT:foo>" ) <EOL> assert foo . src == "<STR_LIT:foo>" <EOL> assert len ( foo . branches ) == <NUM_LIT:1> <EOL> assert foo . branches [ <NUM_LIT:0> ] . name == "<STR_LIT>" <EOL> assert foo . branches [ <NUM_LIT:0> ] . tracks == "<STR_LIT>" <EOL> assert not foo . remotes <EOL> bar = git_wt . get_git_project ( "<STR_LIT:bar>" ) <EOL> assert bar . src == "<STR_LIT:bar>" <EOL> assert len ( bar . branches ) == <NUM_LIT:1> <EOL> assert len ( bar . remotes ) == <NUM_LIT:2> <EOL> origin = bar . remotes [ <NUM_LIT:0> ] <EOL> assert origin . name == "<STR_LIT>" <EOL> assert origin . url == "<STR_LIT>" <EOL> gerrit = bar . remotes [ <NUM_LIT:1> ] <EOL> assert gerrit . name == "<STR_LIT>" <EOL> assert origin . url == "<STR_LIT>" <EOL> def test_git_configs_are_persistent ( git_worktree ) : <EOL> foo = git_worktree . create_git_project ( "<STR_LIT:foo>" ) <EOL> upstream = Remote ( ) <EOL> upstream . name = "<STR_LIT>" <EOL> upstream . url = "<STR_LIT>" <EOL> foo . configure_remote ( upstream ) <EOL> foo . configure_branch ( "<STR_LIT>" , tracks = "<STR_LIT>" ) <EOL> foo . save_config ( ) <EOL> def check_config ( foo ) : <EOL> assert len ( foo . remotes ) == <NUM_LIT:1> <EOL> upstream = foo . remotes [ <NUM_LIT:0> ] <EOL> assert upstream . name == "<STR_LIT>" <EOL> assert upstream . url == "<STR_LIT>" <EOL> assert len ( foo . branches ) == <NUM_LIT:1> <EOL> master = foo . branches [ <NUM_LIT:0> ] <EOL> assert master . name == "<STR_LIT>" <EOL> assert master . tracks == "<STR_LIT>" <EOL> check_config ( foo ) <EOL> wt2 = qisrc . worktree . GitWorkTree ( git_worktree . worktree ) <EOL> foo2 = wt2 . get_git_project ( "<STR_LIT:foo>" ) <EOL> check_config ( foo2 ) <EOL> def test_clone_missing_simple ( git_worktree , git_server ) : <EOL> foo_repo = git_server . create_repo ( "<STR_LIT:foo>" ) <EOL> git_worktree . clone_missing ( foo_repo ) <EOL> assert len ( git_worktree . git_projects ) == <NUM_LIT:1> <EOL> def test_clone_missing_create_subdirs ( git_worktree , git_server ) : <EOL> foo_repo = git_server . create_repo ( "<STR_LIT:foo>" , src = "<STR_LIT>" ) <EOL> git_worktree . clone_missing ( foo_repo ) <EOL> assert len ( git_worktree . git_projects ) == <NUM_LIT:1> <EOL> foo_proj = git_worktree . get_git_project ( "<STR_LIT>" ) <EOL> assert foo_proj <EOL> def test_clone_missing_wrong_branch ( git_worktree , git_server , record_messages ) : <EOL> foo_repo = git_server . create_repo ( "<STR_LIT:foo>" ) <EOL> foo_repo . default_branch = "<STR_LIT>" <EOL> git_worktree . clone_missing ( foo_repo ) <EOL> assert not git_worktree . git_projects <EOL> new_git_worktree = qisrc . worktree . GitWorkTree ( git_worktree . worktree ) <EOL> assert not new_git_worktree . git_projects <EOL> def test_network_error_while_cloning ( git_worktree , git_server ) : <EOL> foo_repo = git_server . create_repo ( "<STR_LIT:foo>" ) <EOL> srv_temp = git_server . root . join ( "<STR_LIT>" ) <EOL> srv = git_server . root . join ( "<STR_LIT>" ) <EOL> srv . rename ( srv_temp ) <EOL> git_worktree . clone_missing ( foo_repo ) <EOL> assert not git_worktree . git_projects <EOL> srv_temp . rename ( srv ) <EOL> git_worktree . clone_missing ( foo_repo ) <EOL> assert len ( git_worktree . git_projects ) == <NUM_LIT:1> <EOL> def test_clone_missing_evil_nested ( git_worktree , git_server ) : <EOL> foo_bar_repo = git_server . create_repo ( "<STR_LIT>" ) <EOL> git_server . push_file ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> foo_repo = git_server . create_repo ( "<STR_LIT:foo>" ) <EOL> git_worktree . clone_missing ( foo_bar_repo ) <EOL> git_server . push_file ( "<STR_LIT:foo>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> git_worktree . clone_missing ( foo_repo ) <EOL> assert len ( git_worktree . git_projects ) == <NUM_LIT:2> <EOL> def test_clone_missing_already_correct ( git_worktree , git_server , record_messages ) : <EOL> foo_repo = git_server . create_repo ( "<STR_LIT>" ) <EOL> git_worktree . clone_missing ( foo_repo ) <EOL> git_worktree . worktree . remove_project ( "<STR_LIT>" ) <EOL> git_worktree . clone_missing ( foo_repo ) <EOL> assert record_messages . find ( "<STR_LIT>" ) is None <EOL> def test_clone_missing_empty ( git_worktree , git_server , record_messages ) : <EOL> foo_repo = git_server . create_repo ( "<STR_LIT:foo>" ) <EOL> foo_path = git_worktree . tmpdir . ensure ( "<STR_LIT:foo>" , dir = True ) <EOL> git = qisrc . git . Git ( foo_path . strpath ) <EOL> git . init ( ) <EOL> git_worktree . clone_missing ( foo_repo ) <EOL> assert record_messages . find ( "<STR_LIT>" ) <EOL> def test_read_groups ( git_worktree , git_server ) : <EOL> manifest_url = git_server . manifest_url <EOL> git_server . create_group ( "<STR_LIT>" , [ "<STR_LIT:foo>" , "<STR_LIT:bar>" ] ) <EOL> git_server . create_group ( "<STR_LIT>" , [ "<STR_LIT:a>" , "<STR_LIT:b>" ] ) <EOL> git_server . create_repo ( "<STR_LIT>" ) <EOL> git_worktree . configure_manifest ( manifest_url ) <EOL> expected_srcs = [ "<STR_LIT:a>" , "<STR_LIT:b>" , "<STR_LIT:bar>" , "<STR_LIT:foo>" ] <EOL> expected = [ git_worktree . get_git_project ( x ) for x in expected_srcs ] <EOL> actual = git_worktree . get_git_projects ( groups = [ "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> assert expected == actual </s>
