1
0
mirror of https://github.com/arsenetar/dupeguru.git synced 2024-11-18 21:19:01 +00:00
dupeguru/base/py/tests/export_test.py
hsoft d1f460b091 Moving the 'py' folder into 'base'.
--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
2009-06-18 18:55:00 +00:00

84 lines
3.1 KiB
Python

# 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 .. import export
from ..export import *
class TCoutput_columns_xml(TestCase):
def test_empty_columns(self):
f = StringIO()
output_column_xml(f,[])
f.seek(0)
doc = minidom.parse(f)
root = doc.documentElement
self.assertEqual('columns',root.nodeName)
self.assertEqual(0,len(root.childNodes))
def test_some_columns(self):
f = StringIO()
output_column_xml(f,[('foo',True),('bar',False),('baz',True)])
f.seek(0)
doc = minidom.parse(f)
columns = doc.getElementsByTagName('column')
self.assertEqual(3,len(columns))
c1,c2,c3 = columns
self.assertEqual('foo',c1.getAttribute('display'))
self.assertEqual('bar',c2.getAttribute('display'))
self.assertEqual('baz',c3.getAttribute('display'))
self.assertEqual('y',c1.getAttribute('enabled'))
self.assertEqual('n',c2.getAttribute('enabled'))
self.assertEqual('y',c3.getAttribute('enabled'))
class TCmerge_css_into_xhtml(TestCase):
def test_main(self):
css = StringIO()
css.write('foobar')
css.seek(0)
xhtml = StringIO()
xhtml.write("""<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>dupeGuru - Duplicate file scanner</title>
<link rel="SHORTCUT ICON" href="/favicon.ico" />
<link rel="stylesheet" href="../hardcoded.css" type="text/css" />
</head>
<body>
</body>
</html>""")
xhtml.seek(0)
self.assert_(merge_css_into_xhtml(xhtml,css))
xhtml.seek(0)
doc = minidom.parse(xhtml)
head = doc.getElementsByTagName('head')[0]
#A style node should have been added in head.
styles = head.getElementsByTagName('style')
self.assertEqual(1,len(styles))
style = styles[0]
self.assertEqual('text/css',style.getAttribute('type'))
self.assertEqual('foobar',style.firstChild.nodeValue.strip())
#all <link rel="stylesheet"> should be removed
self.assertEqual(1,len(head.getElementsByTagName('link')))
def test_empty(self):
self.assert_(not merge_css_into_xhtml(StringIO(),StringIO()))
def test_malformed(self):
xhtml = StringIO()
xhtml.write("""<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">""")
xhtml.seek(0)
self.assert_(not merge_css_into_xhtml(xhtml,StringIO()))