本文整理汇总了Python中files.helpers.DiffHelper.primary_files方法的典型用法代码示例。如果您正苦于以下问题:Python DiffHelper.primary_files方法的具体用法?Python DiffHelper.primary_files怎么用?Python DiffHelper.primary_files使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类files.helpers.DiffHelper
的用法示例。
在下文中一共展示了DiffHelper.primary_files方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestDiffHelper
# 需要导入模块: from files.helpers import DiffHelper [as 别名]
# 或者: from files.helpers.DiffHelper import primary_files [as 别名]
class TestDiffHelper(test_utils.TestCase):
def setUp(self):
dictionary = 'apps/files/fixtures/files/dictionary-test.xpi'
src = os.path.join(settings.ROOT, dictionary)
file_one = Mock()
file_one.id = file_one.pk = 1
file_one.file_path = src
file_two = Mock()
file_two.id = file_two.pk = 2
file_two.file_path = src
self.helper = DiffHelper(file_one, file_two)
def tearDown(self):
self.helper.cleanup()
def test_files_not_extracted(self):
eq_(self.helper.is_extracted, False)
def test_files_extracted(self):
self.helper.extract()
eq_(self.helper.is_extracted, True)
def test_primary_files(self):
eq_(self.helper.file_one.get_files(), self.helper.primary_files())
def test_diffable(self):
self.helper.extract()
self.helper.select('install.js')
assert self.helper.is_diffable()
def test_diffable_one_missing(self):
self.helper.extract()
os.remove(os.path.join(self.helper.file_two.dest, 'install.js'))
self.helper.select('install.js')
assert not self.helper.is_diffable()
eq_(unicode(self.helper.status),
'install.js does not exist in file 2.')
def test_diffable_both_missing(self):
self.helper.extract()
self.helper.select('foo.js')
assert not self.helper.is_diffable()
def test_diffable_one_binary_same(self):
self.helper.extract()
self.helper.select('install.js')
self.helper.one['binary'] = True
assert self.helper.is_binary()
assert not self.helper.is_different()
def test_diffable_one_binary_diff(self):
self.helper.extract()
self.change(self.helper.file_one.dest, 'asd')
cache.clear()
self.helper.select('install.js')
self.helper.one['binary'] = True
assert self.helper.is_binary()
assert self.helper.is_different()
def test_diffable_two_binary_diff(self):
self.helper.extract()
self.change(self.helper.file_one.dest, 'asd')
self.change(self.helper.file_two.dest, 'asd123')
cache.clear()
self.helper.select('install.js')
self.helper.one['binary'] = True
self.helper.two['binary'] = True
assert self.helper.is_binary()
assert self.helper.is_different()
def test_diffable_one_directory(self):
self.helper.extract()
self.helper.select('install.js')
self.helper.one['directory'] = True
assert not self.helper.is_diffable()
eq_(unicode(self.helper.status),
'install.js is a directory in file 1.')
def change(self, file, text):
path = os.path.join(file, 'install.js')
data = open(path, 'r').read()
data += text
open(path, 'w').write(data)