本文整理汇总了Python中sourcetree.SourceTree.run_command方法的典型用法代码示例。如果您正苦于以下问题:Python SourceTree.run_command方法的具体用法?Python SourceTree.run_command怎么用?Python SourceTree.run_command使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sourcetree.SourceTree
的用法示例。
在下文中一共展示了SourceTree.run_command方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_running_interactive_command
# 需要导入模块: from sourcetree import SourceTree [as 别名]
# 或者: from sourcetree.SourceTree import run_command [as 别名]
def test_running_interactive_command(self):
sourcetree = SourceTree()
command = "python3 -c \"print('input please?'); a = input();print('OK' if a=='yes' else 'NO')\""
output = sourcetree.run_command(command, user_input='no')
assert 'NO' in output
output = sourcetree.run_command(command, user_input='yes')
assert 'OK' in output
示例2: test_running_interactive_command
# 需要导入模块: from sourcetree import SourceTree [as 别名]
# 或者: from sourcetree.SourceTree import run_command [as 别名]
def test_running_interactive_command(self):
sourcetree = SourceTree()
sourcetree.run_command("mkdir superlists", cwd=sourcetree.tempdir)
command = "python3 -c \"print('input please?'); a = input();print('OK' if a=='yes' else 'NO')\""
output = sourcetree.run_command(command, user_input="no")
assert "NO" in output
output = sourcetree.run_command(command, user_input="yes")
assert "OK" in output
示例3: test_checks_out_repo_current_chapter_as_master
# 需要导入模块: from sourcetree import SourceTree [as 别名]
# 或者: from sourcetree.SourceTree import run_command [as 别名]
def test_checks_out_repo_current_chapter_as_master(self):
sourcetree = SourceTree()
sourcetree.get_local_repo_path = lambda c: os.path.abspath(os.path.join(os.path.dirname(__file__), "testrepo"))
sourcetree.start_with_checkout(21)
remotes = sourcetree.run_command("git remote").split()
assert remotes == ["repo"]
branch = sourcetree.run_command("git branch").strip()
assert branch == "* master"
diff = sourcetree.run_command("git diff repo/chapter_20").strip()
assert diff == ""
示例4: test_special_cases_wget_bootstrap
# 需要导入模块: from sourcetree import SourceTree [as 别名]
# 或者: from sourcetree.SourceTree import run_command [as 别名]
def test_special_cases_wget_bootstrap(self):
sourcetree = SourceTree()
sourcetree.run_command("mkdir superlists", cwd=sourcetree.tempdir)
with patch("sourcetree.subprocess") as mock_subprocess:
mock_subprocess.Popen.return_value.communicate.return_value = ("bla bla", None)
sourcetree.run_command(BOOTSTRAP_WGET)
assert not mock_subprocess.Popen.called
assert os.path.exists(os.path.join(sourcetree.tempdir, "superlists", "bootstrap.zip"))
diff = sourcetree.run_command(
"diff %s bootstrap.zip" % (os.path.join(os.path.dirname(__file__), "..", "downloads", "bootstrap-3.0.zip"))
)
assert diff == ""
示例5: test_checks_out_repo_chapter_as_master
# 需要导入模块: from sourcetree import SourceTree [as 别名]
# 或者: from sourcetree.SourceTree import run_command [as 别名]
def test_checks_out_repo_chapter_as_master(self):
sourcetree = SourceTree()
sourcetree.get_local_repo_path = lambda c: os.path.abspath(os.path.join(
os.path.dirname(__file__), 'testrepo'
))
sourcetree.start_with_checkout('chapter_17', 'chapter_16')
remotes = sourcetree.run_command('git remote').split()
assert remotes == ['repo']
branch = sourcetree.run_command('git branch').strip()
assert branch == '* master'
diff = sourcetree.run_command('git diff repo/chapter_16').strip()
assert diff == ''
示例6: test_special_cases_fab_deploy
# 需要导入模块: from sourcetree import SourceTree [as 别名]
# 或者: from sourcetree.SourceTree import run_command [as 别名]
def test_special_cases_fab_deploy(self, mock_subprocess):
mock_subprocess.Popen.return_value.returncode = 0
mock_subprocess.Popen.return_value.communicate.return_value = 'a', 'b'
sourcetree = SourceTree()
sourcetree.run_command('fab deploy:[email protected]')
expected = (
'cd deploy_tools &&'
' fab -D -i'
' ~/Dropbox/Book/.vagrant/machines/default/virtualbox/private_key'
' deploy:[email protected]'
)
assert mock_subprocess.Popen.call_args[0][0] == expected
示例7: test_special_cases_wget_bootstrap
# 需要导入模块: from sourcetree import SourceTree [as 别名]
# 或者: from sourcetree.SourceTree import run_command [as 别名]
def test_special_cases_wget_bootstrap(self):
sourcetree = SourceTree()
sourcetree.run_command('mkdir superlists', cwd=sourcetree.tempdir)
with patch('sourcetree.subprocess') as mock_subprocess:
mock_subprocess.Popen.return_value.communicate.return_value = (
'bla bla', None
)
sourcetree.run_command(BOOTSTRAP_WGET)
assert not mock_subprocess.Popen.called
assert os.path.exists(os.path.join(sourcetree.tempdir, 'superlists', 'bootstrap.zip'))
diff = sourcetree.run_command('diff %s bootstrap.zip' % (
os.path.join(os.path.dirname(__file__), '..', 'downloads', 'bootstrap.zip'))
)
assert diff == ''
示例8: test_cleanup_kills_backgrounded_processes_and_rmdirs
# 需要导入模块: from sourcetree import SourceTree [as 别名]
# 或者: from sourcetree.SourceTree import run_command [as 别名]
def test_cleanup_kills_backgrounded_processes_and_rmdirs(self):
sourcetree = SourceTree()
sourcetree.run_command('python -c"import time; time.sleep(5)" & #runserver', cwd=sourcetree.tempdir)
assert len(sourcetree.processes) == 1
sourcetree_pid = sourcetree.processes[0].pid
pids = subprocess.check_output('pgrep -f time.sleep', shell=True).decode('utf8').split()
print('sourcetree_pid', sourcetree_pid)
print('pids', pids)
sids = []
for pid in reversed(pids):
print('checking', pid)
cmd = 'ps -o sid --no-header -p %s' % (pid,)
print(cmd)
try:
sid = subprocess.check_output(cmd, shell=True)
print('sid', sid)
sids.append(sid)
assert sourcetree_pid == int(sid)
except subprocess.CalledProcessError:
pass
assert sids
sourcetree.cleanup()
assert 'time.sleep' not in subprocess.check_output('ps auxf', shell=True).decode('utf8')
示例9: test_running_simple_command
# 需要导入模块: from sourcetree import SourceTree [as 别名]
# 或者: from sourcetree.SourceTree import run_command [as 别名]
def test_running_simple_command(self):
sourcetree = SourceTree()
sourcetree.run_command('touch foo', cwd=sourcetree.tempdir)
assert os.path.exists(os.path.join(sourcetree.tempdir, 'foo'))
示例10: test_environment_variables
# 需要导入模块: from sourcetree import SourceTree [as 别名]
# 或者: from sourcetree.SourceTree import run_command [as 别名]
def test_environment_variables(self):
sourcetree = SourceTree()
os.environ['TEHFOO'] = 'baz'
output = sourcetree.run_command('echo $TEHFOO', cwd=sourcetree.tempdir)
assert output.strip() == 'baz'
示例11: test_doesnt_raise_for_some_things_where_a_return_code_is_ok
# 需要导入模块: from sourcetree import SourceTree [as 别名]
# 或者: from sourcetree.SourceTree import run_command [as 别名]
def test_doesnt_raise_for_some_things_where_a_return_code_is_ok(self):
sourcetree = SourceTree()
sourcetree.run_command('diff foo bar', cwd=sourcetree.tempdir)
sourcetree.run_command('python test.py', cwd=sourcetree.tempdir)
示例12: test_returns_output
# 需要导入模块: from sourcetree import SourceTree [as 别名]
# 或者: from sourcetree.SourceTree import run_command [as 别名]
def test_returns_output(self):
sourcetree = SourceTree()
output = sourcetree.run_command('echo hello', cwd=sourcetree.tempdir)
assert output == 'hello\n'
示例13: test_raises_on_errors
# 需要导入模块: from sourcetree import SourceTree [as 别名]
# 或者: from sourcetree.SourceTree import run_command [as 别名]
def test_raises_on_errors(self):
sourcetree = SourceTree()
with self.assertRaises(Exception):
sourcetree.run_command('synt!tax error', cwd=sourcetree.tempdir)
sourcetree.run_command('synt!tax error', cwd=sourcetree.tempdir, ignore_errors=True)
示例14: test_default_directory_is_superlists
# 需要导入模块: from sourcetree import SourceTree [as 别名]
# 或者: from sourcetree.SourceTree import run_command [as 别名]
def test_default_directory_is_superlists(self):
sourcetree = SourceTree()
os.makedirs(os.path.join(sourcetree.tempdir, 'superlists'))
sourcetree.run_command('touch foo')
assert os.path.exists(os.path.join(sourcetree.tempdir, 'superlists', 'foo'))
示例15: ApplyFromGitRefTest
# 需要导入模块: from sourcetree import SourceTree [as 别名]
# 或者: from sourcetree.SourceTree import run_command [as 别名]
class ApplyFromGitRefTest(unittest.TestCase):
def setUp(self):
self.sourcetree = SourceTree()
self.sourcetree.get_local_repo_path = lambda c: os.path.abspath(os.path.join(
os.path.dirname(__file__), 'testrepo'
))
self.sourcetree.start_with_checkout(17)
self.sourcetree.run_command('git checkout test-start')
self.sourcetree.run_command('git reset')
def test_from_real_git_stuff(self):
listing = CodeListing(filename='file1.txt', contents=dedent(
"""
file 1 line 2 amended
file 1 line 3
""").lstrip()
)
listing.commit_ref = 'ch17l021'
self.sourcetree.apply_listing_from_commit(listing)
with open(self.sourcetree.tempdir + '/superlists/file1.txt') as f:
assert f.read() == dedent(
"""
file 1 line 1
file 1 line 2 amended
file 1 line 3
""").lstrip()
assert listing.was_written
def test_leaves_staging_empty(self):
listing = CodeListing(filename='file1.txt', contents=dedent(
"""
file 1 line 2 amended
file 1 line 3
""").lstrip()
)
listing.commit_ref = 'ch17l021'
self.sourcetree.apply_listing_from_commit(listing)
staged = self.sourcetree.run_command('git diff --staged')
assert staged == ''
def test_raises_if_wrong_file(self):
listing = CodeListing(filename='file2.txt', contents=dedent(
"""
file 1 line 1
file 1 line 2 amended
file 1 line 3
""").lstrip()
)
listing.commit_ref = 'ch17l021'
with self.assertRaises(ApplyCommitException):
self.sourcetree.apply_listing_from_commit(listing)
def _checkout_commit(self, commit):
commit_spec = self.sourcetree.get_commit_spec(commit)
self.sourcetree.run_command('git checkout ' + commit_spec)
self.sourcetree.run_command('git reset')
def test_raises_if_too_many_files_in_commit(self):
listing = CodeListing(filename='file1.txt', contents=dedent(
"""
file 1 line 1
file 1 line 2
""").lstrip()
)
listing.commit_ref = 'ch17l023'
self._checkout_commit('ch17l022')
with self.assertRaises(ApplyCommitException):
self.sourcetree.apply_listing_from_commit(listing)
def test_raises_if_listing_doesnt_show_all_new_lines_in_diff(self):
listing = CodeListing(filename='file1.txt', contents=dedent(
"""
file 1 line 3
""").lstrip()
)
listing.commit_ref = 'ch17l021'
with self.assertRaises(ApplyCommitException):
self.sourcetree.apply_listing_from_commit(listing)
def test_raises_if_listing_lines_in_wrong_order(self):
listing = CodeListing(filename='file1.txt', contents=dedent(
"""
file 1 line 3
#.........这里部分代码省略.........