diff --git a/py/ignore_test.py b/py/ignore_test.py deleted file mode 100644 index 8ff91f52..00000000 --- a/py/ignore_test.py +++ /dev/null @@ -1,158 +0,0 @@ -#!/usr/bin/env python -""" -Unit Name: ignore -Created By: Virgil Dupras -Created On: 2006/05/02 -Last modified by:$Author: virgil $ -Last modified on:$Date: 2009-05-28 15:22:39 +0200 (Thu, 28 May 2009) $ - $Revision: 4385 $ -Copyright 2004-2006 Hardcoded Software (http://www.hardcoded.net) -""" -import unittest -import cStringIO -import xml.dom.minidom - -from .ignore import * - -class TCIgnoreList(unittest.TestCase): - def test_empty(self): - il = IgnoreList() - self.assertEqual(0,len(il)) - self.assert_(not il.AreIgnored('foo','bar')) - - def test_simple(self): - il = IgnoreList() - il.Ignore('foo','bar') - self.assert_(il.AreIgnored('foo','bar')) - self.assert_(il.AreIgnored('bar','foo')) - self.assert_(not il.AreIgnored('foo','bleh')) - self.assert_(not il.AreIgnored('bleh','bar')) - self.assertEqual(1,len(il)) - - def test_multiple(self): - il = IgnoreList() - il.Ignore('foo','bar') - il.Ignore('foo','bleh') - il.Ignore('bleh','bar') - il.Ignore('aybabtu','bleh') - self.assert_(il.AreIgnored('foo','bar')) - self.assert_(il.AreIgnored('bar','foo')) - self.assert_(il.AreIgnored('foo','bleh')) - self.assert_(il.AreIgnored('bleh','bar')) - self.assert_(not il.AreIgnored('aybabtu','bar')) - self.assertEqual(4,len(il)) - - def test_clear(self): - il = IgnoreList() - il.Ignore('foo','bar') - il.Clear() - self.assert_(not il.AreIgnored('foo','bar')) - self.assert_(not il.AreIgnored('bar','foo')) - self.assertEqual(0,len(il)) - - def test_add_same_twice(self): - il = IgnoreList() - il.Ignore('foo','bar') - il.Ignore('bar','foo') - self.assertEqual(1,len(il)) - - def test_save_to_xml(self): - 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 - self.assertEqual('ignore_list',root.nodeName) - children = [c for c in root.childNodes if c.localName] - self.assertEqual(2,len(children)) - self.assertEqual(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'] - self.assertEqual(3,len(subchildren)) - - def test_SaveThenLoad(self): - 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) - self.assertEqual(4,len(il)) - self.assert_(il.AreIgnored(u'\u00e9','bar')) - - def test_LoadXML_with_empty_file_tags(self): - f = cStringIO.StringIO() - f.write('') - f.seek(0) - il = IgnoreList() - il.load_from_xml(f) - self.assertEqual(0,len(il)) - - def test_AreIgnore_works_when_a_child_is_a_key_somewhere_else(self): - il = IgnoreList() - il.Ignore('foo','bar') - il.Ignore('bar','baz') - self.assert_(il.AreIgnored('bar','foo')) - - - def test_no_dupes_when_a_child_is_a_key_somewhere_else(self): - il = IgnoreList() - il.Ignore('foo','bar') - il.Ignore('bar','baz') - il.Ignore('bar','foo') - self.assertEqual(2,len(il)) - - def test_iterate(self): - #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 - self.assert_(not expected) #expected should be empty - - def test_filter(self): - il = IgnoreList() - il.Ignore('foo','bar') - il.Ignore('bar','baz') - il.Ignore('foo','baz') - il.Filter(lambda f,s: f == 'bar') - self.assertEqual(1,len(il)) - self.assert_(not il.AreIgnored('foo','bar')) - self.assert_(il.AreIgnored('bar','baz')) - - def test_save_with_non_ascii_non_unicode_items(self): - il = IgnoreList() - il.Ignore('\xac','\xbf') - f = cStringIO.StringIO() - try: - il.save_to_xml(f) - except Exception,e: - self.fail(str(e)) - - def test_len(self): - il = IgnoreList() - self.assertEqual(0,len(il)) - il.Ignore('foo','bar') - self.assertEqual(1,len(il)) - - def test_nonzero(self): - il = IgnoreList() - self.assert_(not il) - il.Ignore('foo','bar') - self.assert_(il) - - -if __name__ == "__main__": - unittest.main() - diff --git a/py/tests/__init__.py b/py/tests/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/py/app_cocoa_test.py b/py/tests/app_cocoa_test.py similarity index 96% rename from py/app_cocoa_test.py rename to py/tests/app_cocoa_test.py index 54d901b5..60d2e83d 100644 --- a/py/app_cocoa_test.py +++ b/py/tests/app_cocoa_test.py @@ -1,13 +1,9 @@ -#!/usr/bin/env python -""" -Unit Name: dupeguru.tests.app_cocoa -Created By: Virgil Dupras -Created On: 2006/11/11 -Last modified by:$Author: virgil $ -Last modified on:$Date: 2009-05-29 17:51:41 +0200 (Fri, 29 May 2009) $ - $Revision: 4409 $ -Copyright 2006 Hardcoded Software (http://www.hardcoded.net) -""" +# Unit Name: dupeguru.tests.app_cocoa_test +# Created By: Virgil Dupras +# Created On: 2006/11/11 +# $Id$ +# Copyright 2009 Hardcoded Software (http://www.hardcoded.net) + import tempfile import shutil import logging @@ -18,13 +14,13 @@ from hsutil.decorators import log_calls import hsfs.phys import os.path as op -from . import engine, data +from .results_test import GetTestGroups +from .. import engine, data try: - from .app_cocoa import DupeGuru as DupeGuruBase, DGDirectory + from ..app_cocoa import DupeGuru as DupeGuruBase, DGDirectory except ImportError: from nose.plugins.skip import SkipTest raise SkipTest("These tests can only be run on OS X") -from .results_test import GetTestGroups class DupeGuru(DupeGuruBase): def __init__(self): diff --git a/py/app_test.py b/py/tests/app_test.py similarity index 92% rename from py/app_test.py rename to py/tests/app_test.py index 812a0553..fbb6afc3 100644 --- a/py/app_test.py +++ b/py/tests/app_test.py @@ -1,14 +1,9 @@ -#!/usr/bin/env python -""" -Unit Name: dupeguru.tests.app -Created By: Virgil Dupras -Created On: 2007-06-23 -Last modified by:$Author: virgil $ -Last modified on:$Date: 2009-05-28 16:02:48 +0200 (Thu, 28 May 2009) $ - $Revision: 4388 $ -Copyright 2007 Hardcoded Software (http://www.hardcoded.net) -""" -import unittest +# Unit Name: dupeguru.tests.app_test +# Created By: Virgil Dupras +# Created On: 2007-06-23 +# $Id$ +# Copyright 2009 Hardcoded Software (http://www.hardcoded.net) + import os from hsutil.testcase import TestCase @@ -20,8 +15,8 @@ import hsfs.phys import hsutil.files from hsutil.job import nulljob -from . import data, app -from .app import DupeGuru as DupeGuruBase +from .. import data, app +from ..app import DupeGuru as DupeGuruBase class DupeGuru(DupeGuruBase): def __init__(self): @@ -132,6 +127,3 @@ class TCDupeGuru_clean_empty_dirs(TestCase): self.assertEqual(Path('not-empty/empty'), calls[1]['path']) self.assertEqual(Path('not-empty'), calls[2]['path']) - -if __name__ == '__main__': - unittest.main() \ No newline at end of file diff --git a/py/picture/block_test.py b/py/tests/block_test.py similarity index 96% rename from py/picture/block_test.py rename to py/tests/block_test.py index a06cf617..25d97783 100644 --- a/py/picture/block_test.py +++ b/py/tests/block_test.py @@ -1,17 +1,13 @@ -#!/usr/bin/env python -""" -Unit Name: tests.picture.block -Created By: Virgil Dupras -Created On: 2006/09/01 -Last modified by:$Author: virgil $ -Last modified on:$Date: 2009-05-28 15:22:39 +0200 (Thu, 28 May 2009) $ - $Revision: 4385 $ -Copyright 2004-2006 Hardcoded Software (http://www.hardcoded.net) -""" +# Unit Name: tests.picture.block +# Created By: Virgil Dupras +# Created On: 2006/09/01 +# $Id$ +# Copyright 2009 Hardcoded Software (http://www.hardcoded.net) # The commented out tests are tests for function that have been converted to pure C for speed + import unittest -from .block import * +from ..picture.block import * def my_avgdiff(first, second, limit=768, min_iter=3): # this is so I don't have to re-write every call return avgdiff(first, second, limit, min_iter) @@ -307,7 +303,4 @@ class TCavgdiff(unittest.TestCase): # expected1 = 5 + 10 + 15 # expected2 = 0 + 250 + 10 # self.assertEqual(expected1,maxdiff(blocks1,blocks2,expected1 - 1)) -# - -if __name__ == "__main__": - unittest.main() \ No newline at end of file +# \ No newline at end of file diff --git a/py/picture/cache_test.py b/py/tests/cache_test.py similarity index 87% rename from py/picture/cache_test.py rename to py/tests/cache_test.py index f453112f..c16f330e 100644 --- a/py/picture/cache_test.py +++ b/py/tests/cache_test.py @@ -1,23 +1,19 @@ -#!/usr/bin/env python -""" -Unit Name: tests.picture.cache -Created By: Virgil Dupras -Created On: 2006/09/14 -Last modified by:$Author: virgil $ -Last modified on:$Date: 2009-05-28 15:22:39 +0200 (Thu, 28 May 2009) $ - $Revision: 4385 $ -Copyright 2004-2006 Hardcoded Software (http://www.hardcoded.net) -""" -import unittest +# Unit Name: dupeguru.tests.cache_test +# Created By: Virgil Dupras +# Created On: 2006/09/14 +# $Id$ +# Copyright 2009 Hardcoded Software (http://www.hardcoded.net) + from StringIO import StringIO import os.path as op import os import threading from hsutil.testcase import TestCase -from .cache import * -class TCcolors_to_string(unittest.TestCase): +from ..picture.cache import * + +class TCcolors_to_string(TestCase): def test_no_color(self): self.assertEqual('',colors_to_string([])) @@ -30,7 +26,7 @@ class TCcolors_to_string(unittest.TestCase): self.assertEqual('000102030405',colors_to_string([(0,1,2),(3,4,5)])) -class TCstring_to_colors(unittest.TestCase): +class TCstring_to_colors(TestCase): def test_empty(self): self.assertEqual([],string_to_colors('')) @@ -118,7 +114,7 @@ class TCCache(TestCase): self.assertEqual(c[foo_id], b) -class TCCacheSQLEscape(unittest.TestCase): +class TCCacheSQLEscape(TestCase): def test_contains(self): c = Cache() self.assert_("foo'bar" not in c) @@ -140,7 +136,7 @@ class TCCacheSQLEscape(unittest.TestCase): self.fail() -class TCCacheThreaded(unittest.TestCase): +class TCCacheThreaded(TestCase): def test_access_cache(self): def thread_run(): try: @@ -154,6 +150,3 @@ class TCCacheThreaded(unittest.TestCase): t.join() self.assertEqual([(1,2,3)], c['foo']) - -if __name__ == "__main__": - unittest.main() \ No newline at end of file diff --git a/py/directories_test.py b/py/tests/directories_test.py similarity index 95% rename from py/directories_test.py rename to py/tests/directories_test.py index 7d34c343..5b22f542 100644 --- a/py/directories_test.py +++ b/py/tests/directories_test.py @@ -1,14 +1,9 @@ -#!/usr/bin/env python -""" -Unit Name: dupeguru.tests.directories -Created By: Virgil Dupras -Created On: 2006/02/27 -Last modified by:$Author: virgil $ -Last modified on:$Date: 2009-05-29 08:51:14 +0200 (Fri, 29 May 2009) $ - $Revision: 4398 $ -Copyright 2004-2006 Hardcoded Software (http://www.hardcoded.net) -""" -import unittest +# Unit Name: dupeguru.tests.directories_test +# Created By: Virgil Dupras +# Created On: 2006/02/27 +# $Id$ +# Copyright 2009 Hardcoded Software (http://www.hardcoded.net) + import os.path as op import os import time @@ -20,7 +15,7 @@ from hsutil.testcase import TestCase import hsfs.phys from hsfs.phys import phys_test -from directories import * +from ..directories import * testpath = Path(TestCase.datadirpath()) @@ -275,6 +270,3 @@ class TCDirectories(TestCase): self.assert_(isinstance(d.add_path(p2), hsfs.phys.Directory)) self.assert_(isinstance(d.add_path(p1), MySpecialDirclass)) - -if __name__ == "__main__": - unittest.main() \ No newline at end of file diff --git a/py/engine_test.py b/py/tests/engine_test.py similarity index 98% rename from py/engine_test.py rename to py/tests/engine_test.py index 8e9706d9..bd0851ec 100644 --- a/py/engine_test.py +++ b/py/tests/engine_test.py @@ -1,22 +1,17 @@ -#!/usr/bin/env python -""" -Unit Name: dupeguru.engine_test -Created By: Virgil Dupras -Created On: 2006/01/29 -Last modified by:$Author: virgil $ -Last modified on:$Date: $ - $Revision: $ -Copyright 2004-2008 Hardcoded Software (http://www.hardcoded.net) -""" -import unittest +# Unit Name: dupeguru.tests.engine_test +# Created By: Virgil Dupras +# Created On: 2006/01/29 +# $Id$ +# Copyright 2009 Hardcoded Software (http://www.hardcoded.net) + import sys from hsutil import job from hsutil.decorators import log_calls from hsutil.testcase import TestCase -from . import engine -from .engine import * +from .. import engine +from ..engine import * class NamedObject(object): def __init__(self, name="foobar", with_words=False): @@ -817,6 +812,3 @@ class TCget_groups(TestCase): self.assertEqual(0,self.log[0]) self.assertEqual(100,self.log[-1]) - -if __name__ == "__main__": - unittest.main() diff --git a/py/export_test.py b/py/tests/export_test.py similarity index 87% rename from py/export_test.py rename to py/tests/export_test.py index 5c4a6d87..9469936b 100644 --- a/py/export_test.py +++ b/py/tests/export_test.py @@ -1,21 +1,16 @@ -#!/usr/bin/env python -""" -Unit Name: dupeguru.tests.export -Created By: Virgil Dupras -Created On: 2006/09/16 -Last modified by:$Author: virgil $ -Last modified on:$Date: 2009-05-28 15:22:39 +0200 (Thu, 28 May 2009) $ - $Revision: 4385 $ -Copyright 2004-2006 Hardcoded Software (http://www.hardcoded.net) -""" -import unittest +# Unit Name: dupeguru.tests.export_test +# Created By: Virgil Dupras +# Created On: 2006/09/16 +# $Id$ +# Copyright 2009 Hardcoded Software (http://www.hardcoded.net) + from xml.dom import minidom from StringIO import StringIO from hsutil.testcase import TestCase -from .export import * -from . import export +from .. import export +from ..export import * class TCoutput_columns_xml(TestCase): def test_empty_columns(self): @@ -86,6 +81,3 @@ class TCmerge_css_into_xhtml(TestCase): xhtml.seek(0) self.assert_(not merge_css_into_xhtml(xhtml,StringIO())) - -if __name__ == "__main__": - unittest.main() \ No newline at end of file diff --git a/py/tests/ignore_test.py b/py/tests/ignore_test.py new file mode 100644 index 00000000..b19283d4 --- /dev/null +++ b/py/tests/ignore_test.py @@ -0,0 +1,149 @@ +# 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('') + 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 diff --git a/py/results_test.py b/py/tests/results_test.py similarity index 98% rename from py/results_test.py rename to py/tests/results_test.py index 1e74efc6..096e9d4e 100644 --- a/py/results_test.py +++ b/py/tests/results_test.py @@ -1,13 +1,9 @@ -#!/usr/bin/env python -""" -Unit Name: dupeguru.tests.results -Created By: Virgil Dupras -Created On: 2006/02/23 -Last modified by:$Author: virgil $ -Last modified on:$Date: 2009-05-28 15:22:39 +0200 (Thu, 28 May 2009) $ - $Revision: 4385 $ -Copyright 2004-2006 Hardcoded Software (http://www.hardcoded.net) -""" +# Unit Name: dupeguru.tests.results_test +# Created By: Virgil Dupras +# Created On: 2006/02/23 +# $Id$ +# Copyright 2009 Hardcoded Software (http://www.hardcoded.net) + import unittest import StringIO import xml.dom.minidom @@ -18,9 +14,8 @@ from hsutil.testcase import TestCase from hsutil.misc import first from . import engine_test -from . import data -from . import engine -from .results import * +from .. import data, engine +from ..results import * class NamedObject(engine_test.NamedObject): size = 1 @@ -715,7 +710,7 @@ class TCResultsFilter(TestCase): self.assertEqual(expected, self.results.stat_line) -class TCResultsRefFile(unittest.TestCase): +class TCResultsRefFile(TestCase): def setUp(self): self.results = Results(data) self.objects, self.matches, self.groups = GetTestGroups() @@ -737,6 +732,3 @@ class TCResultsRefFile(unittest.TestCase): expected = '0 / 2 (0.00 B / 2.00 B) duplicates marked.' self.assertEqual(expected, self.results.stat_line) - -if __name__ == "__main__": - unittest.main() diff --git a/py/scanner_test.py b/py/tests/scanner_test.py similarity index 96% rename from py/scanner_test.py rename to py/tests/scanner_test.py index 89ad1417..8a4510a1 100644 --- a/py/scanner_test.py +++ b/py/tests/scanner_test.py @@ -1,22 +1,16 @@ -#!/usr/bin/env python -""" -Unit Name: dupeguru.tests.scanner -Created By: Virgil Dupras -Created On: 2006/03/03 -Last modified by:$Author: virgil $ -Last modified on:$Date: 2009-05-28 15:22:39 +0200 (Thu, 28 May 2009) $ - $Revision: 4385 $ -Copyright 2004-2006 Hardcoded Software (http://www.hardcoded.net) -""" -import unittest +# Unit Name: dupeguru.tests.scanner_test +# Created By: Virgil Dupras +# Created On: 2006/03/03 +# $Id$ +# Copyright 2009 Hardcoded Software (http://www.hardcoded.net) from hsutil import job from hsutil.path import Path from hsutil.testcase import TestCase -from .engine import getwords, Match -from .ignore import IgnoreList -from .scanner import * +from ..engine import getwords, Match +from ..ignore import IgnoreList +from ..scanner import * class NamedObject(object): def __init__(self, name="foobar", size=1): @@ -463,6 +457,3 @@ class TCScannerME(TestCase): [group] = s.GetDupeGroups([o1, o2]) self.assertTrue(group.ref is o2) - -if __name__ == "__main__": - unittest.main() \ No newline at end of file