mirror of
https://github.com/arsenetar/dupeguru.git
synced 2024-11-18 13:09:02 +00:00
d1f460b091
--HG-- rename : py/__init__.py => base/py/__init__.py rename : py/app.py => base/py/app.py rename : py/app_cocoa.py => base/py/app_cocoa.py rename : py/app_me_cocoa.py => base/py/app_me_cocoa.py rename : py/app_pe_cocoa.py => base/py/app_pe_cocoa.py rename : py/app_se_cocoa.py => base/py/app_se_cocoa.py rename : py/data.py => base/py/data.py rename : py/data_me.py => base/py/data_me.py rename : py/data_pe.py => base/py/data_pe.py rename : py/directories.py => base/py/directories.py rename : py/engine.py => base/py/engine.py rename : py/export.py => base/py/export.py rename : py/gen.py => base/py/gen.py rename : py/ignore.py => base/py/ignore.py rename : py/modules/block/block.pyx => base/py/modules/block/block.pyx rename : py/modules/block/setup.py => base/py/modules/block/setup.py rename : py/modules/cache/cache.pyx => base/py/modules/cache/cache.pyx rename : py/modules/cache/setup.py => base/py/modules/cache/setup.py rename : py/picture/__init__.py => base/py/picture/__init__.py rename : py/picture/block.py => base/py/picture/block.py rename : py/picture/cache.py => base/py/picture/cache.py rename : py/picture/matchbase.py => base/py/picture/matchbase.py rename : py/results.py => base/py/results.py rename : py/scanner.py => base/py/scanner.py rename : py/tests/__init__.py => base/py/tests/__init__.py rename : py/tests/app_cocoa_test.py => base/py/tests/app_cocoa_test.py rename : py/tests/app_test.py => base/py/tests/app_test.py rename : py/tests/block_test.py => base/py/tests/block_test.py rename : py/tests/cache_test.py => base/py/tests/cache_test.py rename : py/tests/directories_test.py => base/py/tests/directories_test.py rename : py/tests/engine_test.py => base/py/tests/engine_test.py rename : py/tests/export_test.py => base/py/tests/export_test.py rename : py/tests/ignore_test.py => base/py/tests/ignore_test.py rename : py/tests/results_test.py => base/py/tests/results_test.py rename : py/tests/scanner_test.py => base/py/tests/scanner_test.py extra : convert_revision : svn%3Ac306627e-7827-47d3-bdf0-9a457c9553a1/trunk%4074
150 lines
3.8 KiB
Python
150 lines
3.8 KiB
Python
# Unit Name: dupeguru.tests.ignore_test
|
|
# Created By: Virgil Dupras
|
|
# Created On: 2006/05/02
|
|
# $Id$
|
|
# Copyright 2009 Hardcoded Software (http://www.hardcoded.net)
|
|
|
|
import cStringIO
|
|
import xml.dom.minidom
|
|
|
|
from nose.tools import eq_
|
|
|
|
from ..ignore import *
|
|
|
|
def test_empty():
|
|
il = IgnoreList()
|
|
eq_(0,len(il))
|
|
assert not il.AreIgnored('foo','bar')
|
|
|
|
def test_simple():
|
|
il = IgnoreList()
|
|
il.Ignore('foo','bar')
|
|
assert il.AreIgnored('foo','bar')
|
|
assert il.AreIgnored('bar','foo')
|
|
assert not il.AreIgnored('foo','bleh')
|
|
assert not il.AreIgnored('bleh','bar')
|
|
eq_(1,len(il))
|
|
|
|
def test_multiple():
|
|
il = IgnoreList()
|
|
il.Ignore('foo','bar')
|
|
il.Ignore('foo','bleh')
|
|
il.Ignore('bleh','bar')
|
|
il.Ignore('aybabtu','bleh')
|
|
assert il.AreIgnored('foo','bar')
|
|
assert il.AreIgnored('bar','foo')
|
|
assert il.AreIgnored('foo','bleh')
|
|
assert il.AreIgnored('bleh','bar')
|
|
assert not il.AreIgnored('aybabtu','bar')
|
|
eq_(4,len(il))
|
|
|
|
def test_clear():
|
|
il = IgnoreList()
|
|
il.Ignore('foo','bar')
|
|
il.Clear()
|
|
assert not il.AreIgnored('foo','bar')
|
|
assert not il.AreIgnored('bar','foo')
|
|
eq_(0,len(il))
|
|
|
|
def test_add_same_twice():
|
|
il = IgnoreList()
|
|
il.Ignore('foo','bar')
|
|
il.Ignore('bar','foo')
|
|
eq_(1,len(il))
|
|
|
|
def test_save_to_xml():
|
|
il = IgnoreList()
|
|
il.Ignore('foo','bar')
|
|
il.Ignore('foo','bleh')
|
|
il.Ignore('bleh','bar')
|
|
f = cStringIO.StringIO()
|
|
il.save_to_xml(f)
|
|
f.seek(0)
|
|
doc = xml.dom.minidom.parse(f)
|
|
root = doc.documentElement
|
|
eq_('ignore_list',root.nodeName)
|
|
children = [c for c in root.childNodes if c.localName]
|
|
eq_(2,len(children))
|
|
eq_(2,len([c for c in children if c.nodeName == 'file']))
|
|
f1,f2 = children
|
|
subchildren = [c for c in f1.childNodes if c.localName == 'file'] +\
|
|
[c for c in f2.childNodes if c.localName == 'file']
|
|
eq_(3,len(subchildren))
|
|
|
|
def test_SaveThenLoad():
|
|
il = IgnoreList()
|
|
il.Ignore('foo','bar')
|
|
il.Ignore('foo','bleh')
|
|
il.Ignore('bleh','bar')
|
|
il.Ignore(u'\u00e9','bar')
|
|
f = cStringIO.StringIO()
|
|
il.save_to_xml(f)
|
|
f.seek(0)
|
|
il = IgnoreList()
|
|
il.load_from_xml(f)
|
|
eq_(4,len(il))
|
|
assert il.AreIgnored(u'\u00e9','bar')
|
|
|
|
def test_LoadXML_with_empty_file_tags():
|
|
f = cStringIO.StringIO()
|
|
f.write('<?xml version="1.0" encoding="utf-8"?><ignore_list><file><file/></file></ignore_list>')
|
|
f.seek(0)
|
|
il = IgnoreList()
|
|
il.load_from_xml(f)
|
|
eq_(0,len(il))
|
|
|
|
def test_AreIgnore_works_when_a_child_is_a_key_somewhere_else():
|
|
il = IgnoreList()
|
|
il.Ignore('foo','bar')
|
|
il.Ignore('bar','baz')
|
|
assert il.AreIgnored('bar','foo')
|
|
|
|
|
|
def test_no_dupes_when_a_child_is_a_key_somewhere_else():
|
|
il = IgnoreList()
|
|
il.Ignore('foo','bar')
|
|
il.Ignore('bar','baz')
|
|
il.Ignore('bar','foo')
|
|
eq_(2,len(il))
|
|
|
|
def test_iterate():
|
|
#It must be possible to iterate through ignore list
|
|
il = IgnoreList()
|
|
expected = [('foo','bar'),('bar','baz'),('foo','baz')]
|
|
for i in expected:
|
|
il.Ignore(i[0],i[1])
|
|
for i in il:
|
|
expected.remove(i) #No exception should be raised
|
|
assert not expected #expected should be empty
|
|
|
|
def test_filter():
|
|
il = IgnoreList()
|
|
il.Ignore('foo','bar')
|
|
il.Ignore('bar','baz')
|
|
il.Ignore('foo','baz')
|
|
il.Filter(lambda f,s: f == 'bar')
|
|
eq_(1,len(il))
|
|
assert not il.AreIgnored('foo','bar')
|
|
assert il.AreIgnored('bar','baz')
|
|
|
|
def test_save_with_non_ascii_non_unicode_items():
|
|
il = IgnoreList()
|
|
il.Ignore('\xac','\xbf')
|
|
f = cStringIO.StringIO()
|
|
try:
|
|
il.save_to_xml(f)
|
|
except Exception as e:
|
|
raise AssertionError(unicode(e))
|
|
|
|
def test_len():
|
|
il = IgnoreList()
|
|
eq_(0,len(il))
|
|
il.Ignore('foo','bar')
|
|
eq_(1,len(il))
|
|
|
|
def test_nonzero():
|
|
il = IgnoreList()
|
|
assert not il
|
|
il.Ignore('foo','bar')
|
|
assert il
|