Initial hacking to start handling explicit file/contents
Change-Id: I359dd280ce9edef56789c086cc377238238700e4
This commit is contained in:
parent
3f753dfac9
commit
5083834643
@ -299,29 +299,36 @@ class GitFixture(fixtures.Fixture):
|
|||||||
if self._graph:
|
if self._graph:
|
||||||
self.gittree = GitTree(self, self._graph, self._branches)
|
self.gittree = GitTree(self, self._graph, self._branches)
|
||||||
|
|
||||||
def _create_file(self):
|
def _create_file(self, filename=None, contents=None):
|
||||||
|
if not contents:
|
||||||
contents = "\n\n".join(loremipsum.get_paragraphs(3))
|
contents = "\n\n".join(loremipsum.get_paragraphs(3))
|
||||||
|
|
||||||
# always want to ensure the files added to the repo are unique no
|
# always want to ensure the files added to the repo are unique no
|
||||||
# matter which branch they are added to, as otherwise there may
|
# matter which branch they are added to, as otherwise there may
|
||||||
# be conflicts caused by replaying local changes and performing
|
# be conflicts caused by replaying local changes and performing
|
||||||
# merges
|
# merges
|
||||||
|
if filename is None:
|
||||||
while True:
|
while True:
|
||||||
tmpfile = tempfile.NamedTemporaryFile(
|
tmpfile = tempfile.NamedTemporaryFile(
|
||||||
dir=self.repo.working_dir, delete=False)
|
dir=self.repo.working_dir, delete=False)
|
||||||
|
# close immediately to ensure code at the end of this can
|
||||||
|
# be reopened for writing
|
||||||
|
tmpfile.close()
|
||||||
if tmpfile.name not in self._file_list:
|
if tmpfile.name not in self._file_list:
|
||||||
self._file_list.add(tmpfile.name)
|
self._file_list.add(tmpfile.name)
|
||||||
|
filename = tmpfile.name
|
||||||
break
|
break
|
||||||
# case where same filename in use on a different branch
|
# remove file as name in use elsewhere in the git repo
|
||||||
tmpfile.close()
|
|
||||||
os.remove(tmpfile.name)
|
os.remove(tmpfile.name)
|
||||||
|
|
||||||
tmpfile.write(contents.encode('utf-8'))
|
with open(filename, 'w') as f:
|
||||||
tmpfile.close()
|
f.write(contents.encode('utf-8'))
|
||||||
return tmpfile.name
|
|
||||||
|
|
||||||
def _create_file_commit(self, change_id=None, message_prefix=None):
|
return filename
|
||||||
filename = self._create_file()
|
|
||||||
|
def _create_file_commit(self, message=None, contents=None,
|
||||||
|
change_id=None, message_prefix=None):
|
||||||
|
filename = self._create_file(contents)
|
||||||
self.repo.git.add(filename)
|
self.repo.git.add(filename)
|
||||||
message = "Adding %s" % os.path.basename(filename)
|
message = "Adding %s" % os.path.basename(filename)
|
||||||
if message_prefix:
|
if message_prefix:
|
||||||
|
0
tests/advanced/__init__.py
Normal file
0
tests/advanced/__init__.py
Normal file
34
tests/advanced/test_fixture.py
Normal file
34
tests/advanced/test_fixture.py
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
# Copyright (c) 2014 Hewlett-Packard Development Company, L.P.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
# implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
#
|
||||||
|
|
||||||
|
import testtools
|
||||||
|
|
||||||
|
import fixtures_git
|
||||||
|
|
||||||
|
|
||||||
|
class TestBuildTree(testtools.TestCase):
|
||||||
|
|
||||||
|
def test_basic(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def test_merge(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def test_merge_and_replace(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def test_merge_unrelated_history(self):
|
||||||
|
pass
|
Loading…
Reference in New Issue
Block a user