Exemple #1
0
    def test_exception_class(self):
        document = PwDocument()

        with self.assertRaises(XmlDocumentError):
            document.get_fortran_input()

        schema = os.path.join(self.schemas_dir, 'qes.xsd')
        document = TdSpectrumDocument(schema=schema)
        document.read(
            os.path.join(self.test_dir, 'resources/pw/Al001_relax_bfgs.xml'))

        with self.assertRaises(XmlDocumentError):
            document.get_fortran_input()
Exemple #2
0
    def test_incomplete_schema(self):
        schema_path = os.path.join(self.test_dir,
                                   'resources/dummy/incomplete.xsd')
        document = PwDocument(schema=schema_path)

        xml_filename = os.path.join(self.test_dir,
                                    'resources/dummy/incomplete.xml')
        document.read(xml_filename)

        with self.assertRaises(XmlDocumentError) as ctx:
            document.get_fortran_input()
        self.assertEqual(str(ctx.exception),
                         "Missing input './input' in XML data!")

        document.root.append(ElementTree.Element('input'))
        with self.assertRaises(XmlDocumentError) as ctx:
            document.get_fortran_input()
        self.assertEqual(str(ctx.exception),
                         "Missing input element in XSD schema!")
Exemple #3
0
    def test_fortran_input_generator(self):
        xml_filename = os.path.join(self.test_dir,
                                    'resources/pw/Al001_relax_bfgs.xml')
        document = PwDocument()
        document.read(xml_filename)

        self.assertFalse(os.path.isfile(self.output_file))

        document.write_fortran_input(self.output_file)
        with open(self.output_file) as f:
            fortran_input = f.read()

        if os.path.isfile(self.output_file):
            os.unlink(self.output_file)
        self.assertFalse(os.path.isfile(self.output_file))

        self.assertEqual(fortran_input[:9], '&CONTROL\n')
        self.assertEqual(fortran_input, document.get_fortran_input())