def test_end_to_end_cached_self_stdout(self):
        """Complete test using cache getting no ancestors or descendants and
        writing the result to stdout."""
        cache_fname = LocalDataGrabber.data_file(
            'end-to-end-30484')
        sys.argv = ['geneagrapher', '--cache-file', cache_fname, '30484']
        self.ggrapher.parse_input()
        self.assertEqual(self.ggrapher.get_ancestors, False)
        self.assertEqual(self.ggrapher.get_descendants, False)
        self.assertEqual(self.ggrapher.verbose, False)
        self.assertEqual(self.ggrapher.write_filename, None)
        self.assertEqual(self.ggrapher.seed_ids, [30484])

        self.ggrapher.build_graph_complete(CacheGrabber,
                                           filename=self.ggrapher.cache_file)

        # Redirect stdout to capture output.
        stdout = sys.stdout
        stdout_intercept = StringIO.StringIO()
        sys.stdout = stdout_intercept
        self.ggrapher.generate_dot_file()
        sys.stdout = stdout

        expected = u"""digraph genealogy {
    graph [charset="utf-8"];
    node [shape=plaintext];
    edge [style=bold];

    30484 [label="Peter Chris Pappas \\nThe Pennsylvania State University \
(1982)"];

}
"""
        self.assertEqual(stdout_intercept.getvalue().decode('utf-8'), expected)
    def test_end_to_end_through_ggrapher_self_stdout(self):
        """Complete test calling ggrapher getting no ancestors or descendants
        and writing the result to stdout."""
        cache_fname = LocalDataGrabber.data_file(
            'end-to-end-30484')
        sys.argv = ['geneagrapher', '--cache-file', cache_fname, '30484']

        # Redirect stdout to capture output.
        stdout = sys.stdout
        stdout_intercept = StringIO.StringIO()
        sys.stdout = stdout_intercept
        geneagrapher.ggrapher()
        sys.stdout = stdout

        expected = u"""digraph genealogy {
    graph [charset="utf-8"];
    node [shape=plaintext];
    edge [style=bold];

    30484 [label="Peter Chris Pappas \\nThe Pennsylvania State University \
(1982)"];

}
"""
        self.assertEqual(stdout_intercept.getvalue().decode('utf-8'), expected)
    def test_build_graph_complete_only_self_verbose_cache_grabber(self):
        """Graph building with no ancestors or descendants using the cache
        grabber to verify its verbose printing."""
        self.ggrapher.verbose = True
        self.ggrapher.seed_ids.append(127946)

        # Redirect stdout to capture output.
        stdout = sys.stdout
        stdout_intercept = StringIO.StringIO()
        sys.stdout = stdout_intercept
        cache_fname = LocalDataGrabber.data_file(
            'geneagrapher_verbose_cache_grabber_test')
        expiration = 1e15
        self.ggrapher.build_graph_complete(CacheGrabber, filename=cache_fname,
                                           expiration_interval=expiration)
        sys.stdout = stdout

        self.assertEqual(stdout_intercept.getvalue().decode('utf-8'),
                         u"Grabbing record #127946...cache hit\n")
 def data_file(self, filename):
     """Return the absolute path to the data file with given name."""
     return LocalDataGrabber.data_file(filename)