Esempio n. 1
0
 def test_explain(self):
     query = Query(['col1'])
     expected = """
         Data Source:
           <none given> (assuming Selector object)
         Execution Plan:
           getattr, (<RESULT>, '_select'), {}
           <RESULT>, (['col1']), {}
     """
     expected = textwrap.dedent(expected).strip()
     self.assertEqual(query._explain(file=None), expected)
Esempio n. 2
0
    def test_explain2(self):
        query = Query(['label1'])

        expected = """
            Data Source:
              <none given> (assuming Selector object)
            Execution Plan:
              getattr, (<RESULT>, '_select'), {}
              <RESULT>, (['label1']), {}
        """
        expected = textwrap.dedent(expected).strip()

        # Defaults to stdout (redirected to StringIO for testing).
        string_io = io.StringIO()
        returned_value = query._explain(file=string_io)
        self.assertIsNone(returned_value)

        printed_value = string_io.getvalue().strip()
        self.assertEqual(printed_value, expected)

        # Get result as string.
        returned_value = query._explain(file=None)
        self.assertEqual(returned_value, expected)