def it_should_lock_all_dependencies_when_enabled(config): gitman.update(depth=1, lock=True) expect(config.__mapper__.text) == CONFIG + strip( """ sources_locked: - name: gitman_1 type: git repo: https://github.com/jacebrowning/gitman-demo sparse_paths: - rev: 1de84ca1d315f81b035cd7b0ecf87ca2025cdacd link: scripts: - - name: gitman_2 type: git repo: https://github.com/jacebrowning/gitman-demo sparse_paths: - rev: 7bd138fe7359561a8c2ff9d195dff238794ccc04 link: scripts: - - name: gitman_3 type: git repo: https://github.com/jacebrowning/gitman-demo sparse_paths: - rev: 9bf18e16b956041f0267c21baad555a23237b52e link: scripts: - """ )
def it_should_not_lock_dependnecies_when_disabled(config): config.__mapper__.text = strip(""" location: deps sources: - name: gitman_1 repo: https://github.com/jacebrowning/gitman-demo rev: example-branch link: scripts: - - name: gitman_2 repo: https://github.com/jacebrowning/gitman-demo rev: example-tag link: scripts: - sources_locked: - name: gitman_2 repo: https://github.com/jacebrowning/gitman-demo rev: (old revision) link: scripts: - """) gitman.update(depth=1, lock=False) expect(config.__mapper__.text) == strip(""" location: deps sources: - name: gitman_1 repo: https://github.com/jacebrowning/gitman-demo rev: example-branch link: scripts: - - name: gitman_2 repo: https://github.com/jacebrowning/gitman-demo rev: example-tag link: scripts: - sources_locked: - name: gitman_2 repo: https://github.com/jacebrowning/gitman-demo rev: (old revision) link: scripts: - """)
def it_locks_previously_locked_dependnecies(config): config.__mapper__.text = strip(""" location: deps sources: - name: gitman_1 repo: https://github.com/jacebrowning/gitman-demo rev: example-branch link: scripts: - - name: gitman_2 repo: https://github.com/jacebrowning/gitman-demo rev: example-tag link: scripts: - sources_locked: - name: gitman_2 repo: https://github.com/jacebrowning/gitman-demo rev: (old revision) link: scripts: - """) gitman.update(depth=1) expect(config.__mapper__.text) == strip(""" location: deps sources: - name: gitman_1 repo: https://github.com/jacebrowning/gitman-demo rev: example-branch link: scripts: - - name: gitman_2 repo: https://github.com/jacebrowning/gitman-demo rev: example-tag link: scripts: - sources_locked: - name: gitman_2 repo: https://github.com/jacebrowning/gitman-demo rev: 7bd138fe7359561a8c2ff9d195dff238794ccc04 link: scripts: - """)
def it_records_all_versions_when_no_arguments(config): expect(gitman.update(depth=1, lock=False)) == True expect(gitman.lock()) == True expect(config.__mapper__.text) == CONFIG + strip(""" sources_locked: - name: gitman_1 repo: https://github.com/jacebrowning/gitman-demo rev: 1de84ca1d315f81b035cd7b0ecf87ca2025cdacd link: scripts: - - name: gitman_2 repo: https://github.com/jacebrowning/gitman-demo rev: 7bd138fe7359561a8c2ff9d195dff238794ccc04 link: scripts: - - name: gitman_3 repo: https://github.com/jacebrowning/gitman-demo rev: 9bf18e16b956041f0267c21baad555a23237b52e link: scripts: - """) == config.__mapper__.text
def it_records_specified_dependencies(config): expect(gitman.update(depth=1, lock=False)) == True expect(gitman.lock('gitman_1', 'gitman_3')) == True expect(config.__mapper__.text) == CONFIG + strip(""" sources_locked: - name: gitman_1 type: git repo: https://github.com/jacebrowning/gitman-demo sparse_paths: - rev: 1de84ca1d315f81b035cd7b0ecf87ca2025cdacd link: scripts: - - name: gitman_3 type: git repo: https://github.com/jacebrowning/gitman-demo sparse_paths: - rev: 9bf18e16b956041f0267c21baad555a23237b52e link: scripts: - groups: [] """) == config.__mapper__.text
def it_should_fail_on_dirty_repositories(config): expect(gitman.update(depth=1, lock=False)) == True shell.rm(os.path.join("deps", "gitman_1", ".project")) try: with pytest.raises(UncommittedChanges): gitman.lock() expect(config.__mapper__.text).does_not_contain("<dirty>") finally: shell.rm(os.path.join("deps", "gitman_1"))
def it_should_not_allow_source_and_group_name_conflicts(config): config.__mapper__.text = strip(""" location: deps sources: - name: gitman_1 type: git repo: https://github.com/jacebrowning/gitman-demo rev: example-branch - name: gitman_2 type: git repo: https://github.com/jacebrowning/gitman-demo rev: example-branch groups: - name: gitman_1 members: - gitman_1 - gitman_2 """) with pytest.raises(InvalidConfig): gitman.update(depth=1, lock=True)
def it_records_all_versions_when_no_arguments(config): expect(gitman.update(depth=1, lock=False)) == True expect(gitman.lock()) == True config.datafile.load() expect(config.datafile.text).contains( strip(""" sources_locked: - name: gitman_1 type: git repo: https://github.com/jacebrowning/gitman-demo sparse_paths: - rev: 1de84ca1d315f81b035cd7b0ecf87ca2025cdacd link: scripts: - - name: gitman_2 type: git repo: https://github.com/jacebrowning/gitman-demo sparse_paths: - rev: 7bd138fe7359561a8c2ff9d195dff238794ccc04 link: scripts: - - name: gitman_3 type: git repo: https://github.com/jacebrowning/gitman-demo sparse_paths: - rev: 9bf18e16b956041f0267c21baad555a23237b52e link: scripts: - """))
def it_should_not_modify_config(config): gitman.update('gitman_1', depth=1) expect(config.__mapper__.text) == CONFIG
def it_locks_dependencies_changes_force_interactive_yes( config, monkeypatch): def git_changes(type, include_untracked=False, display_status=True, _show=False): # get caller function name caller = inspect.stack()[1].function # if caller is update_files then we return True # to simulate local changes if caller == "update_files": return True # all other functions get False because after # the force process there are logically no changes anymore return False # patch the git.changes function to stimulate the # force-interactive question (without changes no question) monkeypatch.setattr('gitman.git.changes', git_changes) # patch standard input function to return "y" for each call # this is necessary to answer the force-interactive question # with yes todo the force process monkeypatch.setattr('builtins.input', lambda x: "y") config.__mapper__.text = strip(""" location: deps sources: - name: gitman_2 type: git repo: https://github.com/jacebrowning/gitman-demo sparse_paths: - rev: example-tag link: scripts: - sources_locked: - name: gitman_2 type: git repo: https://github.com/jacebrowning/gitman-demo sparse_paths: - rev: (old revision) link: scripts: - groups: [] """) gitman.update(depth=1, force_interactive=True) expect(config.__mapper__.text) == strip(""" location: deps sources: - name: gitman_2 type: git repo: https://github.com/jacebrowning/gitman-demo sparse_paths: - rev: example-tag link: scripts: - sources_locked: - name: gitman_2 type: git repo: https://github.com/jacebrowning/gitman-demo sparse_paths: - rev: 7bd138fe7359561a8c2ff9d195dff238794ccc04 link: scripts: - groups: [] """)
def it_should_not_lock_dependencies_changes_force_interactive_no( config, monkeypatch): def git_changes(type, include_untracked=False, display_status=True, _show=False): # always return True because changes won't be overwriten return True # patch the git.changes function to stimulate the # force-interactive question (without changes no question) monkeypatch.setattr('gitman.git.changes', git_changes) # patch standard input function to return "n" for each call # this is necessary to answer the force-interactive question # with no to skip the force process monkeypatch.setattr('builtins.input', lambda x: "n") config.__mapper__.text = strip(""" location: deps sources: - name: gitman_2 type: git repo: https://github.com/jacebrowning/gitman-demo sparse_paths: - rev: example-tag link: scripts: - sources_locked: - name: gitman_2 type: git repo: https://github.com/jacebrowning/gitman-demo sparse_paths: - rev: (old revision) link: scripts: - groups: [] """) gitman.update(depth=1, force_interactive=True) expect(config.__mapper__.text) == strip(""" location: deps sources: - name: gitman_2 type: git repo: https://github.com/jacebrowning/gitman-demo sparse_paths: - rev: example-tag link: scripts: - sources_locked: - name: gitman_2 type: git repo: https://github.com/jacebrowning/gitman-demo sparse_paths: - rev: (old revision) link: scripts: - groups: [] """)
def it_locks_previously_locked_dependnecies_by_group_name(config): config.__mapper__.text = strip(""" location: deps sources: - name: gitman_1 type: git repo: https://github.com/jacebrowning/gitman-demo sparse_paths: - rev: example-branch link: scripts: - - name: gitman_2 type: git repo: https://github.com/jacebrowning/gitman-demo sparse_paths: - rev: example-tag link: scripts: - - name: gitman_3 type: git repo: https://github.com/jacebrowning/gitman-demo sparse_paths: - rev: example-tag link: scripts: - sources_locked: - name: gitman_1 type: git repo: https://github.com/jacebrowning/gitman-demo sparse_paths: - rev: (old revision) link: scripts: - - name: gitman_2 type: git repo: https://github.com/jacebrowning/gitman-demo sparse_paths: - rev: (old revision) link: scripts: - groups: - name: group_a members: - gitman_1 - gitman_2 """) gitman.update('group_a', depth=1) expect(config.__mapper__.text) == strip(""" location: deps sources: - name: gitman_1 type: git repo: https://github.com/jacebrowning/gitman-demo sparse_paths: - rev: example-branch link: scripts: - - name: gitman_2 type: git repo: https://github.com/jacebrowning/gitman-demo sparse_paths: - rev: example-tag link: scripts: - - name: gitman_3 type: git repo: https://github.com/jacebrowning/gitman-demo sparse_paths: - rev: example-tag link: scripts: - sources_locked: - name: gitman_1 type: git repo: https://github.com/jacebrowning/gitman-demo sparse_paths: - rev: 1de84ca1d315f81b035cd7b0ecf87ca2025cdacd link: scripts: - - name: gitman_2 type: git repo: https://github.com/jacebrowning/gitman-demo sparse_paths: - rev: 7bd138fe7359561a8c2ff9d195dff238794ccc04 link: scripts: - groups: - name: group_a members: - gitman_1 - gitman_2 """)
def it_should_not_lock_dependencies_when_disabled(config): config.datafile.text = strip(""" location: deps sources: - name: gitman_1 type: git repo: https://github.com/jacebrowning/gitman-demo sparse_paths: - rev: example-branch link: scripts: - - name: gitman_2 type: git repo: https://github.com/jacebrowning/gitman-demo sparse_paths: - rev: example-tag link: scripts: - sources_locked: - name: gitman_2 type: git repo: https://github.com/jacebrowning/gitman-demo sparse_paths: - rev: (old revision) link: scripts: - groups: - """) config.datafile.load() gitman.update(depth=1, lock=False) expect(config.datafile.text) == strip(""" location: deps sources: - name: gitman_1 type: git repo: https://github.com/jacebrowning/gitman-demo sparse_paths: - rev: example-branch link: scripts: - - name: gitman_2 type: git repo: https://github.com/jacebrowning/gitman-demo sparse_paths: - rev: example-tag link: scripts: - sources_locked: - name: gitman_2 type: git repo: https://github.com/jacebrowning/gitman-demo sparse_paths: - rev: (old revision) link: scripts: - groups: - """)
def it_locks_previously_unlocked_dependencies(config): config.datafile.text = strip(""" location: deps sources: - name: gitman_1 type: git repo: https://github.com/jacebrowning/gitman-demo sparse_paths: - rev: example-branch link: scripts: - - name: gitman_2 type: git repo: https://github.com/jacebrowning/gitman-demo sparse_paths: - rev: example-tag link: scripts: - sources_locked: - name: gitman_2 type: git repo: https://github.com/jacebrowning/gitman-demo sparse_paths: - rev: (old revision) link: scripts: - groups: - """) config.datafile.load() gitman.update(depth=1) config.datafile.load() expect(config.datafile.text) == strip(""" location: deps sources: - name: gitman_1 type: git repo: https://github.com/jacebrowning/gitman-demo sparse_paths: - rev: example-branch link: scripts: - - name: gitman_2 type: git repo: https://github.com/jacebrowning/gitman-demo sparse_paths: - rev: example-tag link: scripts: - sources_locked: - name: gitman_2 type: git repo: https://github.com/jacebrowning/gitman-demo sparse_paths: - rev: 7bd138fe7359561a8c2ff9d195dff238794ccc04 link: scripts: - groups: - """)
def it_should_not_modify_config(config): gitman.update('gitman_1', depth=1) expect(config.datafile.text) == CONFIG