本文整理汇总了Python中files.helpers.DiffHelper.is_diffable方法的典型用法代码示例。如果您正苦于以下问题:Python DiffHelper.is_diffable方法的具体用法?Python DiffHelper.is_diffable怎么用?Python DiffHelper.is_diffable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类files.helpers.DiffHelper
的用法示例。
在下文中一共展示了DiffHelper.is_diffable方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestDiffViewer
# 需要导入模块: from files.helpers import DiffHelper [as 别名]
# 或者: from files.helpers.DiffHelper import is_diffable [as 别名]
class TestDiffViewer(FilesBase, amo.tests.TestCase):
fixtures = ['base/addon_3615', 'base/users']
def setUp(self):
super(TestDiffViewer, self).setUp()
self.file_viewer = DiffHelper(self.files[0], self.files[1])
def poll_url(self):
return reverse('files.compare.poll', args=[self.files[0].pk,
self.files[1].pk])
def add_file(self, file_obj, name, contents):
dest = os.path.join(file_obj.dest, name)
open(dest, 'w').write(contents)
def file_url(self, file=None):
args = [self.files[0].pk, self.files[1].pk]
if file:
args.extend(['file', file])
return reverse('files.compare', args=args)
def check_urls(self, status):
for url in [self.poll_url(), self.file_url()]:
eq_(self.client.get(url).status_code, status)
def test_tree_no_file(self):
self.file_viewer.extract()
res = self.client.get(self.file_url('doesnotexist.js'))
eq_(res.status_code, 404)
def test_content_file(self):
self.file_viewer.extract()
res = self.client.get(self.file_url(not_binary))
doc = pq(res.content)
eq_(len(doc('pre')), 3)
def test_binary_serve_links(self):
self.file_viewer.extract()
res = self.client.get(self.file_url(binary))
doc = pq(res.content)
node = doc('#content-wrapper a')
eq_(len(node), 2)
assert node[0].text.startswith('Download ar.dic')
def test_view_both_present(self):
self.file_viewer.extract()
res = self.client.get(self.file_url(not_binary))
doc = pq(res.content)
eq_(len(doc('pre')), 3)
eq_(len(doc('#content-wrapper p')), 2)
def test_view_one_missing(self):
self.file_viewer.extract()
os.remove(os.path.join(self.file_viewer.right.dest, 'install.js'))
res = self.client.get(self.file_url(not_binary))
doc = pq(res.content)
eq_(len(doc('pre')), 3)
eq_(len(doc('#content-wrapper p')), 1)
def test_view_left_binary(self):
self.file_viewer.extract()
filename = os.path.join(self.file_viewer.left.dest, 'install.js')
open(filename, 'w').write('MZ')
res = self.client.get(self.file_url(not_binary))
assert 'This file is not viewable online' in res.content
def test_view_right_binary(self):
self.file_viewer.extract()
filename = os.path.join(self.file_viewer.right.dest, 'install.js')
open(filename, 'w').write('MZ')
assert not self.file_viewer.is_diffable()
res = self.client.get(self.file_url(not_binary))
assert 'This file is not viewable online' in res.content
def test_different_tree(self):
self.file_viewer.extract()
os.remove(os.path.join(self.file_viewer.left.dest, not_binary))
res = self.client.get(self.file_url(not_binary))
doc = pq(res.content)
eq_(doc('h4:last').text(), 'Deleted files:')
eq_(len(doc('ul.root')), 2)
def test_file_chooser_selection(self):
res = self.client.get(self.file_url())
doc = pq(res.content)
eq_(doc('#id_left option[selected]').attr('value'),
str(self.files[0].id))
eq_(doc('#id_right option[selected]').attr('value'),
str(self.files[1].id))
def test_file_chooser_selection_same_hash(self):
"""
In cases where multiple files are coalesced, the file selector may not
have an actual entry for certain files. Instead, the entry with the
identical hash should be selected.
"""
res = self.client.get(reverse('files.compare',
args=(self.files[0].id,
self.files[2].id)))
#.........这里部分代码省略.........
示例2: TestDiffHelper
# 需要导入模块: from files.helpers import DiffHelper [as 别名]
# 或者: from files.helpers.DiffHelper import is_diffable [as 别名]
class TestDiffHelper(amo.tests.TestCase):
def setUp(self):
src = os.path.join(settings.ROOT, get_file('dictionary-test.xpi'))
self.helper = DiffHelper(make_file(1, src), make_file(2, src))
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_get_files(self):
eq_(self.helper.left.get_files(),
self.helper.get_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.right.dest, 'install.js'))
self.helper.select('install.js')
assert self.helper.is_diffable()
def test_diffable_allow_empty(self):
self.helper.extract()
self.assertRaises(AssertionError, self.helper.right.read_file)
eq_(self.helper.right.read_file(allow_empty=True), '')
def test_diffable_both_missing(self):
self.helper.extract()
self.helper.select('foo.js')
assert not self.helper.is_diffable()
def test_diffable_deleted_files(self):
self.helper.extract()
os.remove(os.path.join(self.helper.left.dest, 'install.js'))
eq_('install.js' in self.helper.get_deleted_files(), True)
def test_diffable_one_binary_same(self):
self.helper.extract()
self.helper.select('install.js')
self.helper.left.selected['binary'] = True
assert self.helper.is_binary()
def test_diffable_one_binary_diff(self):
self.helper.extract()
self.change(self.helper.left.dest, 'asd')
cache.clear()
self.helper.select('install.js')
self.helper.left.selected['binary'] = True
assert self.helper.is_binary()
def test_diffable_two_binary_diff(self):
self.helper.extract()
self.change(self.helper.left.dest, 'asd')
self.change(self.helper.right.dest, 'asd123')
cache.clear()
self.helper.select('install.js')
self.helper.left.selected['binary'] = True
self.helper.right.selected['binary'] = True
assert self.helper.is_binary()
def test_diffable_one_directory(self):
self.helper.extract()
self.helper.select('install.js')
self.helper.left.selected['directory'] = True
assert not self.helper.is_diffable()
assert self.helper.left.selected['msg'].startswith('This file')
def test_diffable_parent(self):
self.helper.extract()
self.change(self.helper.left.dest, 'asd',
filename='__MACOSX/._dictionaries')
cache.clear()
files = self.helper.get_files()
eq_(files['__MACOSX/._dictionaries']['diff'], True)
eq_(files['__MACOSX']['diff'], True)
def change(self, file, text, filename='install.js'):
path = os.path.join(file, filename)
data = open(path, 'r').read()
data += text
open(path, 'w').write(data)
示例3: TestDiffViewer
# 需要导入模块: from files.helpers import DiffHelper [as 别名]
# 或者: from files.helpers.DiffHelper import is_diffable [as 别名]
class TestDiffViewer(FilesBase, amo.tests.WebappTestCase):
fixtures = ['base/apps', 'base/users', 'webapps/337141-steamcube']
def setUp(self):
super(TestDiffViewer, self).setUp()
self.file_viewer = DiffHelper(self.files[0], self.files[1],
is_webapp=True)
def poll_url(self):
return reverse('mkt.files.compare.poll', args=[self.files[0].pk,
self.files[1].pk])
def add_file(self, file_obj, name, contents):
dest = os.path.join(file_obj.dest, name)
open(dest, 'w').write(contents)
def file_url(self, file=None):
args = [self.files[0].pk, self.files[1].pk]
if file:
args.extend(['file', file])
return reverse('mkt.files.compare', args=args)
def check_urls(self, status):
for url in [self.poll_url(), self.file_url()]:
status_code = self.client.get(url).status_code
assert status_code == status, (
'Request to %s returned status code %d (expected %d)' %
(url, status_code, status))
def test_tree_no_file(self):
self.file_viewer.extract()
res = self.client.get(self.file_url('doesnotexist.js'))
eq_(res.status_code, 404)
def test_content_file(self):
self.file_viewer.extract()
res = self.client.get(self.file_url(not_binary))
doc = pq(res.content)
eq_(len(doc('pre')), 3)
def test_binary_serve_links(self):
self.file_viewer.extract()
res = self.client.get(self.file_url(binary))
doc = pq(res.content)
node = doc('#content-wrapper a')
eq_(len(node), 2)
assert node[0].text.startswith('Download 256.png')
def test_view_both_present(self):
self.file_viewer.extract()
res = self.client.get(self.file_url(not_binary))
doc = pq(res.content)
eq_(len(doc('pre')), 3)
eq_(len(doc('#content-wrapper p')), 4)
def test_view_one_missing(self):
self.file_viewer.extract()
os.remove(os.path.join(self.file_viewer.right.dest, 'manifest.webapp'))
res = self.client.get(self.file_url(not_binary))
doc = pq(res.content)
eq_(len(doc('pre')), 3)
eq_(len(doc('#content-wrapper p')), 2)
def test_view_left_binary(self):
self.file_viewer.extract()
filename = os.path.join(self.file_viewer.left.dest, 'manifest.webapp')
open(filename, 'w').write('MZ')
res = self.client.get(self.file_url(not_binary))
assert 'This file is not viewable online' in res.content
def test_view_right_binary(self):
self.file_viewer.extract()
filename = os.path.join(self.file_viewer.right.dest, 'manifest.webapp')
open(filename, 'w').write('MZ')
assert not self.file_viewer.is_diffable()
res = self.client.get(self.file_url(not_binary))
assert 'This file is not viewable online' in res.content
def test_different_tree(self):
self.file_viewer.extract()
os.remove(os.path.join(self.file_viewer.left.dest, not_binary))
res = self.client.get(self.file_url(not_binary))
doc = pq(res.content)
eq_(doc('h4:last').text(), 'Deleted files:')
eq_(len(doc('ul.root')), 2)
def test_file_chooser_selection(self):
res = self.client.get(self.file_url())
doc = pq(res.content)
eq_(doc('#id_left option[selected]').attr('value'),
str(self.files[0].id))
eq_(doc('#id_right option[selected]').attr('value'),
str(self.files[1].id))
示例4: TestDiffHelper
# 需要导入模块: from files.helpers import DiffHelper [as 别名]
# 或者: from files.helpers.DiffHelper import is_diffable [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)
示例5: TestDiffViewer
# 需要导入模块: from files.helpers import DiffHelper [as 别名]
# 或者: from files.helpers.DiffHelper import is_diffable [as 别名]
class TestDiffViewer(FilesBase, test_utils.TestCase):
fixtures = ['base/addon_3615', 'base/users']
def setUp(self):
super(TestDiffViewer, self).setUp()
self.file_viewer = DiffHelper(self.file, self.file_two)
def poll_url(self):
return reverse('files.compare.poll', args=[self.file.pk,
self.file_two.pk])
def add_file(self, file_obj, name, contents):
dest = os.path.join(file_obj.dest, name)
open(dest, 'w').write(contents)
def file_url(self, file=None):
args = [self.file.pk, self.file_two.pk]
if file:
args.extend(['file', file])
return reverse('files.compare', args=args)
def check_urls(self, status):
for url in [self.poll_url(), self.file_url()]:
eq_(self.client.get(url).status_code, status)
def test_tree_no_file(self):
self.file_viewer.extract()
res = self.client.get(self.file_url('doesnotexist.js'))
eq_(res.status_code, 404)
def test_content_file(self):
self.file_viewer.extract()
res = self.client.get(self.file_url(not_binary))
doc = pq(res.content)
eq_(len(doc('pre')), 3)
def test_binary_serve_links(self):
self.file_viewer.extract()
res = self.client.get(self.file_url(binary))
doc = pq(res.content)
node = doc('#content-wrapper a')
eq_(len(node), 2)
assert node[0].text.startswith('Download ar.dic')
def test_view_both_present(self):
self.file_viewer.extract()
res = self.client.get(self.file_url(not_binary))
doc = pq(res.content)
eq_(len(doc('pre')), 3)
eq_(len(doc('#content-wrapper p')), 2)
def test_view_one_missing(self):
self.file_viewer.extract()
os.remove(os.path.join(self.file_viewer.right.dest, 'install.js'))
res = self.client.get(self.file_url(not_binary))
doc = pq(res.content)
eq_(len(doc('pre')), 3)
eq_(len(doc('#content-wrapper p')), 1)
def test_view_left_binary(self):
self.file_viewer.extract()
filename = os.path.join(self.file_viewer.left.dest, 'install.js')
open(filename, 'w').write('MZ')
res = self.client.get(self.file_url(not_binary))
assert 'This file is not viewable online' in res.content
def test_view_right_binary(self):
self.file_viewer.extract()
filename = os.path.join(self.file_viewer.right.dest, 'install.js')
open(filename, 'w').write('MZ')
assert not self.file_viewer.is_diffable()
res = self.client.get(self.file_url(not_binary))
assert 'This file is not viewable online' in res.content
def test_different_tree(self):
self.file_viewer.extract()
os.remove(os.path.join(self.file_viewer.left.dest, not_binary))
res = self.client.get(self.file_url(not_binary))
doc = pq(res.content)
eq_(doc('h4:last').text(), 'Deleted files:')
eq_(len(doc('ul.root')), 2)
示例6: TestDiffHelper
# 需要导入模块: from files.helpers import DiffHelper [as 别名]
# 或者: from files.helpers.DiffHelper import is_diffable [as 别名]
class TestDiffHelper(amo.tests.TestCase):
def setUp(self):
src = os.path.join(settings.ROOT, get_file("dictionary-test.xpi"))
self.helper = DiffHelper(make_file(1, src), make_file(2, src))
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_get_files(self):
eq_(self.helper.left.get_files(), self.helper.get_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.right.dest, "install.js"))
self.helper.select("install.js")
assert self.helper.is_diffable()
def test_diffable_allow_empty(self):
self.helper.extract()
self.assertRaises(AssertionError, self.helper.right.read_file)
eq_(self.helper.right.read_file(allow_empty=True), "")
def test_diffable_both_missing(self):
self.helper.extract()
self.helper.select("foo.js")
assert not self.helper.is_diffable()
def test_diffable_deleted_files(self):
self.helper.extract()
os.remove(os.path.join(self.helper.left.dest, "install.js"))
eq_("install.js" in self.helper.get_deleted_files(), True)
def test_diffable_one_binary_same(self):
self.helper.extract()
self.helper.select("install.js")
self.helper.left.selected["binary"] = True
assert self.helper.is_binary()
def test_diffable_one_binary_diff(self):
self.helper.extract()
self.change(self.helper.left.dest, "asd")
cache.clear()
self.helper.select("install.js")
self.helper.left.selected["binary"] = True
assert self.helper.is_binary()
def test_diffable_two_binary_diff(self):
self.helper.extract()
self.change(self.helper.left.dest, "asd")
self.change(self.helper.right.dest, "asd123")
cache.clear()
self.helper.select("install.js")
self.helper.left.selected["binary"] = True
self.helper.right.selected["binary"] = True
assert self.helper.is_binary()
def test_diffable_one_directory(self):
self.helper.extract()
self.helper.select("install.js")
self.helper.left.selected["directory"] = True
assert not self.helper.is_diffable()
assert self.helper.left.selected["msg"].startswith("This file")
def test_diffable_parent(self):
self.helper.extract()
self.change(self.helper.left.dest, "asd", filename="__MACOSX/._dictionaries")
cache.clear()
files = self.helper.get_files()
eq_(files["__MACOSX/._dictionaries"]["diff"], True)
eq_(files["__MACOSX"]["diff"], True)
def change(self, file, text, filename="install.js"):
path = os.path.join(file, filename)
data = open(path, "r").read()
data += text
open(path, "w").write(data)