def test_catalog_xsd(self): T = Transformer([('demo', 'catalog-xsl')], transformer_registry=self.registry) result = T(catalog_xml) self.assertTrue('<h2>My CD Collection</h2>' in result) self.assertTrue('<tr bgcolor="#9acd32">' in result) self.assertTrue('<td>Bob Dylan</td>' in result)
def test_transformation_1_and_2(self): T = Transformer([('demo', 't1'), ('demo', 't2')], transformer_registry=self.registry) result = T(sample_xml) self.assertTrue(result.count('<foo>') == 0) self.assertTrue(result.count('<bar>') == 3) self.assertTrue('<hello foo="bar">' in result)
def test_catalog_python_xsd_transform(self): T = Transformer([('demo', 'catalog-python'), ('demo', 'catalog-xsl')], transformer_registry=self.registry) result = T(catalog_xml) # running catalog-python first should not have any effect self.assertTrue('<h2>My CD Collection</h2>' in result) self.assertTrue('<tr bgcolor="#9acd32">' in result) self.assertTrue('<table' in result)
def test_catalog_xsd_python_transform(self): T = Transformer([('demo', 'catalog-xsl'), ('demo', 'catalog-python')], transformer_registry=self.registry) result = T(catalog_xml) self.assertTrue('<h2>My CD Collection</h2>' in result) self.assertTrue('<tr bgcolor="#9acd32">' in result) self.assertFalse('<table>' in result) self.assertTrue('<TABELLE' in result)
def test_transformation_with_node(self): T = Transformer([('demo', 't1')], transformer_registry=self.registry) result = T(lxml.etree.fromstring(sample_xml)) self.assertTrue(result.count('<bar>') == 3)
def test_transformation_1(self): T = Transformer([('demo', 't1')], transformer_registry=self.registry) result = T(sample_xml) self.assertTrue(result.count('<bar>') == 3)
def test_verify_steps_failing(self): T = Transformer([('xxx', 'yyy')], transformer_registry=self.registry) with self.assertRaises(ValueError): T.verify_steps()
def test_verify_steps_working(self): T = Transformer([('demo', 't1'), ('demo', 't2')], transformer_registry=self.registry) T.verify_steps()
def test_xslt2_transformation(self): T = Transformer([('demo', 'sample-xslt2')], transformer_registry=self.registry) result = T(sample_xslt2_xml) self.assertTrue('<test xmlns="http://www.example.com/v2">' in result)
def test_transformation_with_debug_option(self): T = Transformer([('demo', 'catalog-xsl'), ('demo', 'catalog-python')], transformer_registry=self.registry) T(catalog_xml, debug=True)
def test_transformation_custom_output_encoding(self): T = Transformer([('demo', 't1')], transformer_registry=self.registry) result = T(sample_xml, output_encoding='utf16') self.assertTrue(not isinstance(result, unicode))
def test_transformation_return_fragment_non_existing_fragment(self): T = Transformer([('demo', 't1')], transformer_registry=self.registry) with self.assertRaises(ValueError): T(sample_xml, return_fragment='XXXXXX')
def test_transformation_return_fragment(self): T = Transformer([('demo', 't1')], transformer_registry=self.registry) result = T(sample_xml, return_fragment='world') self.assertTrue('<hello' not in result)
def test_transformation_2(self): T = Transformer([('demo', 't2')], transformer_registry=self.registry) result = T(sample_xml) self.assertTrue('<hello foo="bar">' in result)
def test_transformation_unicode_without_input_encoding(self): T = Transformer([('demo', 't1')], transformer_registry=self.registry) with self.assertRaises(TypeError): T(sample_xml.encode('utf8'), input_encoding=None)
def test_transformation_improper_root(self): T = Transformer([('demo', 't1')], transformer_registry=self.registry) with self.assertRaises(TypeError): T(object)