本文整理汇总了Python中sourcetree.SourceTree.start_with_checkout方法的典型用法代码示例。如果您正苦于以下问题:Python SourceTree.start_with_checkout方法的具体用法?Python SourceTree.start_with_checkout怎么用?Python SourceTree.start_with_checkout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sourcetree.SourceTree
的用法示例。
在下文中一共展示了SourceTree.start_with_checkout方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_checks_out_repo_current_chapter_as_master
# 需要导入模块: from sourcetree import SourceTree [as 别名]
# 或者: from sourcetree.SourceTree import start_with_checkout [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 == ""
示例2: test_checks_out_repo_chapter_as_master
# 需要导入模块: from sourcetree import SourceTree [as 别名]
# 或者: from sourcetree.SourceTree import start_with_checkout [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 == ''
示例3: ApplyFromGitRefTest
# 需要导入模块: from sourcetree import SourceTree [as 别名]
# 或者: from sourcetree.SourceTree import start_with_checkout [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
#.........这里部分代码省略.........
示例4: ChapterTest
# 需要导入模块: from sourcetree import SourceTree [as 别名]
# 或者: from sourcetree.SourceTree import start_with_checkout [as 别名]
class ChapterTest(unittest.TestCase):
maxDiff = None
def setUp(self):
self.sourcetree = SourceTree()
self.tempdir = self.sourcetree.tempdir
self.processes = []
self.pos = 0
self.dev_server_running = False
self.current_server_cd = None
self.current_server_exports = {}
def tearDown(self):
self.sourcetree.cleanup()
def parse_listings(self):
base_dir = os.path.split(os.path.abspath(os.path.dirname(__file__)))[0]
filename = self.chapter_name + '.html'
with open(os.path.join(base_dir, filename), encoding='utf-8') as f:
raw_html = f.read()
parsed_html = html.fromstring(raw_html)
all_nodes = parsed_html.cssselect('.exampleblock.sourcecode, div:not(.sourcecode) div.listingblock')
listing_nodes = []
for ix, node in enumerate(all_nodes):
prev = all_nodes[ix - 1]
if node not in list(prev.iterdescendants()):
listing_nodes.append(node)
self.listings = [p for n in listing_nodes for p in parse_listing(n)]
def check_final_diff(self, ignore=None, diff=None):
if diff is None:
diff = self.run_command(Command(
'git diff -w repo/{}'.format(self.chapter_name)
))
try:
print('checking final diff', diff)
except io.BlockingIOError:
pass
self.assertNotIn('fatal:', diff)
start_marker = 'diff --git a/\n'
commit = Commit.from_diff(start_marker + diff)
if ignore is None:
if commit.lines_to_add:
self.fail('Found lines to add in diff:\n{}'.format(commit.lines_to_add))
if commit.lines_to_remove:
self.fail('Found lines to remove in diff:\n{}'.format(commit.lines_to_remove))
return
if "moves" in ignore:
ignore.remove("moves")
difference_lines = commit.deleted_lines + commit.new_lines
else:
difference_lines = commit.lines_to_add + commit.lines_to_remove
for line in difference_lines:
if any(ignorable in line for ignorable in ignore):
continue
self.fail('Found divergent line in diff:\n{}'.format(line))
def start_with_checkout(self):
update_sources_for_chapter(self.chapter_name, self.previous_chapter)
self.sourcetree.start_with_checkout(self.chapter_name, self.previous_chapter)
# simulate virtualenv folder
self.sourcetree.run_command('mkdir -p virtualenv/bin virtualenv/lib')
def write_to_file(self, codelisting):
self.assertEqual(
type(codelisting), CodeListing,
"passed a non-Codelisting to write_to_file:\n%s" % (codelisting,)
)
print('writing to file', codelisting.filename)
write_to_file(codelisting, self.tempdir)
def apply_patch(self, codelisting):
tf = tempfile.NamedTemporaryFile(delete=False)
tf.write(codelisting.contents.encode('utf8'))
tf.write('\n'.encode('utf8'))
tf.close()
print('patch:\n', codelisting.contents)
patch_output = self.run_command(
Command('patch --fuzz=3 --no-backup-if-mismatch %s %s' % (codelisting.filename, tf.name))
)
print(patch_output)
self.assertNotIn('malformed', patch_output)
self.assertNotIn('failed', patch_output.lower())
codelisting.was_checked = True
with open(os.path.join(self.tempdir, codelisting.filename)) as f:
print(f.read())
os.remove(tf.name)
self.pos += 1
codelisting.was_written = True
#.........这里部分代码省略.........