def test_charset(self) -> None: doc = WdomDocument(charset='TEST') _re = re.compile( '<meta( charset="TEST"| wdom_id="\d+"){2}>', re.S ) html = doc.build() self.assertIsNotNone(_re.search(html)) self.assertNotIn('utf', html) self.assertEqual('TEST', doc.characterSet)
def test_title(self) -> None: doc = WdomDocument(title='TEST') _re = re.compile( '<title wdom_id="\d+">\s*TEST\s*</title>', re.S ) html = doc.build() self.assertIsNotNone(_re.search(html)) self.assertNotIn('W-DOM', html) self.assertEqual('TEST', doc.title)
def test_tempdir(self): doc = WdomDocument() self.assertIsNotNone(doc.tempdir) self.assertTrue(os.path.exists(doc.tempdir)) self.assertTrue(os.path.isabs(doc.tempdir)) self.assertTrue(os.path.isdir(doc.tempdir)) tempdir = doc.tempdir testfile = os.path.join(tempdir, 'test_file') with open(testfile, 'w') as f: f.write('test') self.assertTrue(os.path.exists(testfile)) self.assertTrue(os.path.isfile(testfile)) with open(testfile) as f: self.assertEqual('test', f.read().strip()) del doc import gc gc.collect() self.assertFalse(os.path.exists(testfile)) self.assertFalse(os.path.exists(tempdir))
def test_create_element_defclass_unknown(self): from wdom import element doc = WdomDocument(default_class=element.HTMLElement) elm = doc.createElement('aa') self.assertEqual(type(elm), element.HTMLElement) self.assertRegex(elm.html, '<aa></aa>')
def test_create_element_defclass(self): from wdom import element doc = WdomDocument(default_class=element.HTMLElement) elm = doc.createElement('a') self.assertEqual(type(elm), A) self.assertRegex(elm.html, '<a wdom_id="\d+"></a>')
def setUp(self): super().setUp() self.doc = WdomDocument()
def setUp(self) -> None: super().setUp() self.doc = WdomDocument() self.doc.defaultView.customElements.reset() server._tornado.connections = [1]