Example #1
0
    def test_custom_directory(self):
        import tempfile
        import os
        import shutil

        handler = Parser.DataHandler(validate=False, escape=False)

        # Create a temporary directory
        tmpdir = tempfile.mkdtemp()
        # Set the custom directory to the temporary directory.
        # This assignment statement will also initialize the local DTD and XSD directories.
        handler.directory = tmpdir

        # Confirm that the two temp directories are named what we want.
        self.assertEqual(
            handler.local_dtd_dir,
            os.path.join(handler.directory, 'Bio', 'Entrez', 'DTDs'))
        self.assertEqual(
            handler.local_xsd_dir,
            os.path.join(handler.directory, 'Bio', 'Entrez', 'XSDs'))

        # And that they were created.
        self.assertTrue(os.path.isdir(handler.local_dtd_dir))
        self.assertTrue(os.path.isdir(handler.local_xsd_dir))
        shutil.rmtree(tmpdir)
Example #2
0
def entrez_dtd_dir(test_dir):
    """Fixes CircleCI failure to retrieve DTDs for Entrez.Parser from NCBI.

    See BioPython GitHub repository for demonstration of ability to pass
    Entrez.Parser a custom directory containting DTDs. Found in
    Tests.test_Entrez.py classCustomDirectoryTest:
    https://github.com/biopython/biopython/blob/master/Tests/test_Entrez.py
    """
    dir_path = test_dir / "test_inputs" / "Bio" / "Entrez" / "DTDs"
    handler = Parser.DataHandler(validate=False, escape=False)
    handler.directory = dir_path
    return