[geneagrapher] 201/226: Add LocalDataGrabber class so tests work with local data.

Doug Torrance dtorrance-guest at moszumanska.debian.org
Sat Jul 11 17:11:10 UTC 2015


This is an automated email from the git hooks/post-receive script.

dtorrance-guest pushed a commit to branch master
in repository geneagrapher.

commit 85da0b9062d8266a3e3fe4cd29fbb5ea79a7cedf
Author: David Alber <alber.david at gmail.com>
Date:   Mon Dec 26 12:42:56 2011 -0800

    Add LocalDataGrabber class so tests work with local data.
    
    This changeset adds the LocalDataGrabber class in the test source
    tree. This class exposes the same interface as Grabber -- so that
    it can be used in place of it -- but is only able to grab test
    data from the local test data directory. This is useful for testing
    without making network requests.
---
 tests/geneagrapher/local_data_grabber.py | 33 ++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/tests/geneagrapher/local_data_grabber.py b/tests/geneagrapher/local_data_grabber.py
new file mode 100644
index 0000000..17b2718
--- /dev/null
+++ b/tests/geneagrapher/local_data_grabber.py
@@ -0,0 +1,33 @@
+import os
+import sys
+from BeautifulSoup import BeautifulSoup
+from geneagrapher.grabber import get_record_from_tree
+
+
+class LocalDataGrabber:
+    """A class for grabbing locally-cached test data."""
+    def __init__(self):
+        pass
+
+    def __enter__(self):
+        return self
+
+    def __exit__(self, exc_type, exc_value, traceback):
+        pass
+
+    @classmethod
+    def data_file(cls, filename):
+        """Return the absolute path to the data file with given name."""
+        return os.path.join(cls.data_path, filename)
+
+    def get_record(self, id):
+        """Load the local data for the given id and use Grabber's functionas
+        to extract the record data."""
+        with open(self.data_file('{0}.html'.format(id)), 'r') as fin:
+            soup = BeautifulSoup(fin, convertEntities='html')
+        return get_record_from_tree(soup, id)
+
+
+file_path = os.path.abspath(__file__)
+LocalDataGrabber.data_path = os.path.join(os.path.dirname(file_path),
+                                          'testdata')

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/geneagrapher.git



More information about the debian-science-commits mailing list