Exemple #1
0
 def test_version_parsing(self):
     with self.subTest("With space"):
         document = Document("")
         document._Document__parse_xml_declaration(
             "<?xml version = '1.0' ?>")
         self.assertEqual("1.0", document.version)
     with self.subTest("Without space"):
         document = Document("")
         document._Document__parse_xml_declaration("<?xml version='1.0'?>")
         self.assertEqual("1.0", document.version)
     with self.subTest("Invalid version 2.0"):
         document = Document("")
         with self.assertRaises(XMLError):
             document._Document__parse_xml_declaration(
                 "<?xml version='2.0'?>")
     with self.subTest("Valid version 1.1"):
         document = Document("")
         document._Document__parse_xml_declaration("<?xml version='1.1'?>")
         self.assertEqual("1.1", document.version)
Exemple #2
0
 def test_invalid_keyword(self):
     with self.subTest("Versionn"):
         document = Document("")
         with self.assertRaises(XMLError):
             document._Document__parse_xml_declaration(
                 "<?xml versionn='1.0'?>")
     with self.subTest("Versio"):
         document = Document("")
         with self.assertRaises(XMLError):
             document._Document__parse_xml_declaration(
                 "<?xml versio='1.0'?>")
     with self.subTest("encodin"):
         document = Document("")
         with self.assertRaises(XMLError):
             document._Document__parse_xml_declaration(
                 "<?xml version='1.0' encodin='utf-8?>")
     with self.subTest("standalne"):
         document = Document("")
         with self.assertRaises(XMLError):
             document._Document__parse_xml_declaration(
                 "<?xml version='1.0' standalne='no'?>")
Exemple #3
0
 def test_missing_whitespace(self):
     with self.subTest("Before version"):
         document = Document("")
         with self.assertRaises(XMLError):
             document._Document__parse_xml_declaration(
                 "<?xmlversion='1.0'?>")
     with self.subTest("After version -> encoding"):
         document = Document("")
         with self.assertRaises(XMLError):
             document._Document__parse_xml_declaration(
                 "<?xml version='1.0'encoding='utf-8'?>")
     with self.subTest("After version -> standalone"):
         document = Document("")
         with self.assertRaises(XMLError):
             document._Document__parse_xml_declaration(
                 "<?xml version='1.0'standalone='no'?>")
     with self.subTest("After encoding -> standalone"):
         document = Document("")
         with self.assertRaises(XMLError):
             document._Document__parse_xml_declaration(
                 "<?xml version='1.0' encoding='utf-8'standalone='no'?>")
Exemple #4
0
 def test_missing_version(self):
     with self.subTest("Encoding"):
         document = Document("")
         with self.assertRaises(XMLError):
             document._Document__parse_xml_declaration(
                 "<?xml encoding='utf-8'?>")
     with self.subTest("Standalone"):
         document = Document("")
         with self.assertRaises(XMLError):
             document._Document__parse_xml_declaration(
                 "<?xml standalone='no'?>")
     with self.subTest("Both"):
         document = Document("")
         with self.assertRaises(XMLError):
             document._Document__parse_xml_declaration(
                 "<?xml encoding='utf-8' standalone='yes'?>")
Exemple #5
0
 def test_misordered_xml_declaration(self):
     with self.subTest("Encoding -> Version"):
         document = Document("")
         with self.assertRaises(XMLError):
             document._Document__parse_xml_declaration(
                 "<?xml encoding='utf-8' version='1.0'?>")
     with self.subTest("Version -> Standalone -> Encoding"):
         document = Document("")
         with self.assertRaises(XMLError):
             document._Document__parse_xml_declaration(
                 "<?xml version='1.0' standalone='no' encoding='utf-8'?>")
     with self.subTest("Standalone -> Version"):
         document = Document("")
         with self.assertRaises(XMLError):
             document._Document__parse_xml_declaration(
                 "<?xml standalone='no' version='1.0'?>")
Exemple #6
0
 def test_standalone_parsing(self):
     with self.subTest("With encoding"):
         document = Document("")
         document._Document__parse_xml_declaration(
             "<?xml version='1.0' encoding='utf-8' standalone='no'?>")
         self.assertEqual("1.0", document.version)
         self.assertEqual("utf-8", document.encoding)
         self.assertEqual(False, document.standalone)
     with self.subTest("Without encoding"):
         document = Document("")
         document._Document__parse_xml_declaration(
             "<?xml version='1.0' standalone='yes'?>")
         self.assertEqual("1.0", document.version)
         self.assertEqual(True, document.standalone)
     with self.subTest("Invalid value"):
         document = Document("")
         with self.assertRaises(XMLError):
             document._Document__parse_xml_declaration(
                 "<?xml version='1.0' standalone='maybe'?>")
Exemple #7
0
 def test_encoding_parsing(self):
     document = Document("")
     document._Document__parse_xml_declaration(
         "<?xml version='1.0' encoding='utf-8'?>")
     self.assertEqual("1.0", document.version)
     self.assertEqual("utf-8", document.encoding)