Esempio n. 1
0
class TestApplicator(unittest.TestCase):
    def setUp(self):
        self.a = EADDir(input_dir=r'C:\Users\wboyle\PycharmProjects\bentley_code\utilities')

    def _method_for_testing_write(self, ead):
        texts = ead.tree.xpath("//text")
        for text in texts:
            text.text = "yo"

    def _method_for_testing_characterize(self, ead):
        results = []
        texts = ead.tree.xpath("//text")
        for text in texts:
            results.append(text.text)
        return results

    def test_ead_list(self):
        self.assertEquals(self.a.ead_files, ['ead_appended.xml', 'ead_messy.xml', 'ead_pretty.xml'])

    def test_characterize_directory(self):
        intended_results = [['text'], ['text'], ['text']]
        self.assertEquals(self.a.characterize_dir(function=self._method_for_testing_characterize), intended_results)

    def test_apply_to_directory(self):
        output_dir = os.path.join(self.a.input_dir, "output")
        self.a.apply_function_to_dir(function=self._method_for_testing_write, output_dir=output_dir)

        b = EADDir(output_dir)
        intended_results = [['yo'], ['yo'], ['yo']]
        self.assertEquals(b.characterize_dir(self._method_for_testing_characterize), intended_results)

        for ead in os.listdir(output_dir):
            os.remove(os.path.join(output_dir, ead))
Esempio n. 2
0
    def test_apply_to_directory(self):
        output_dir = os.path.join(self.a.input_dir, "output")
        self.a.apply_function_to_dir(function=self._method_for_testing_write, output_dir=output_dir)

        b = EADDir(output_dir)
        intended_results = [['yo'], ['yo'], ['yo']]
        self.assertEquals(b.characterize_dir(self._method_for_testing_characterize), intended_results)

        for ead in os.listdir(output_dir):
            os.remove(os.path.join(output_dir, ead))
Esempio n. 3
0
    def test_apply_to_directory(self):
        output_dir = os.path.join(self.a.input_dir, "output")
        self.a.apply_function_to_dir(function=self._method_for_testing_write,
                                     output_dir=output_dir)

        b = EADDir(output_dir)
        intended_results = [['yo'], ['yo'], ['yo']]
        self.assertEquals(
            b.characterize_dir(self._method_for_testing_characterize),
            intended_results)

        for ead in os.listdir(output_dir):
            os.remove(os.path.join(output_dir, ead))
Esempio n. 4
0
class TestApplicator(unittest.TestCase):
    def setUp(self):
        self.a = EADDir(
            input_dir=r'C:\Users\wboyle\PycharmProjects\bentley_code\utilities'
        )

    def _method_for_testing_write(self, ead):
        texts = ead.tree.xpath("//text")
        for text in texts:
            text.text = "yo"

    def _method_for_testing_characterize(self, ead):
        results = []
        texts = ead.tree.xpath("//text")
        for text in texts:
            results.append(text.text)
        return results

    def test_ead_list(self):
        self.assertEquals(
            self.a.ead_files,
            ['ead_appended.xml', 'ead_messy.xml', 'ead_pretty.xml'])

    def test_characterize_directory(self):
        intended_results = [['text'], ['text'], ['text']]
        self.assertEquals(
            self.a.characterize_dir(
                function=self._method_for_testing_characterize),
            intended_results)

    def test_apply_to_directory(self):
        output_dir = os.path.join(self.a.input_dir, "output")
        self.a.apply_function_to_dir(function=self._method_for_testing_write,
                                     output_dir=output_dir)

        b = EADDir(output_dir)
        intended_results = [['yo'], ['yo'], ['yo']]
        self.assertEquals(
            b.characterize_dir(self._method_for_testing_characterize),
            intended_results)

        for ead in os.listdir(output_dir):
            os.remove(os.path.join(output_dir, ead))
import csv

from lxml import etree

from utilities import EADDir

def find_multiple_physdescs(ead):
    results = []
    parents = ead.tree.xpath("//physdesc")
    for parent in parents:
        tags = parent.xpath("extent")
        if len(tags) > 1:
            results.append([ead.filename, ead.tree.getpath(parent), len(tags), etree.tostring(etree.fromstring(etree.tostring(parent)))])

    return results

if __name__ == "__main__":
    input_dir = r'C:\Users\wboyle\PycharmProjects\vandura\Real_Masters_all'
    e = EADDir(input_dir)
    results = e.characterize_dir(find_multiple_physdescs)

    with open("eads_with_multiple_extents.csv", mode="wb") as f:
        writer = csv.writer(f)
        for result in results:
            writer.writerows(result)