コード例 #1
0
    def test_get_output(self):
        jvm = Mock()
        baos = ByteArrayOutputStream()
        baos.jvm = jvm

        baos.get_output()
        baos.jvm_obj.toString().strip.assert_called()
コード例 #2
0
    def test_get_output(self):
        jvm = Mock()
        baos = ByteArrayOutputStream()
        baos.jvm = jvm

        baos.get_output()
        baos.jvm_obj.toString().strip.assert_called()
コード例 #3
0
    def test_jvm_obj(self):
        jvm = Mock()

        baos = ByteArrayOutputStream()
        with self.assertRaises(AttributeError):
            jvm_obj = baos.jvm_obj

        # check that on the second call ByteArrayOutputStream returns the same jvm_obj
        jvm.java.io.ByteArrayOutputStream = Mock(side_effects=[1, 2])
        baos.jvm = jvm
        jvm_obj1 = baos.jvm_obj
        jvm_obj2 = baos.jvm_obj
        self.assertEqual(jvm_obj1, jvm_obj2)
コード例 #4
0
    def test_jvm_obj(self):
        jvm = Mock()

        baos = ByteArrayOutputStream()
        with self.assertRaises(AttributeError):
            jvm_obj = baos.jvm_obj

        # check that on the second call ByteArrayOutputStream returns the same jvm_obj
        jvm.java.io.ByteArrayOutputStream = Mock(
            side_effects=[1, 2]
        )
        baos.jvm = jvm
        jvm_obj1 = baos.jvm_obj
        jvm_obj2 = baos.jvm_obj
        self.assertEqual(jvm_obj1, jvm_obj2)
コード例 #5
0
    def test_output(self):
        with patch("pyddq.reporters.get_field") as get_field:
            baos = ByteArrayOutputStream()
            baos.jvm = self.df._sc._jvm

            get_field.return_value = baos.jvm_obj
            check = Check(self.df).hasUniqueKey("_1").hasUniqueKey("_1", "_2")
            z = Mock()
            reporter = ZeppelinReporter(z)
            check.run([reporter])
            expected_output = """
%html
</p>
<h4>Checking [_1: bigint, _2: string]</h4>
<h5>It has a total number of 2 columns and 3 rows.</h5>
<table>
<tr><td style="padding:3px">&#10060;</td><td style="padding:3px">Column _1 is not a key (1 non-unique tuple).</td></tr>
<tr><td style="padding:3px">&#9989;</td><td style="padding:3px">Columns _1, _2 are a key.</td></tr>
</table>
<p hidden>
""".strip()
            self.assertEqual(baos.get_output(), expected_output)
コード例 #6
0
    def test_output(self):
        with patch("pyddq.reporters.get_field") as get_field:
            baos = ByteArrayOutputStream()
            baos.jvm = self.df._sc._jvm

            get_field.return_value = baos.jvm_obj
            check = Check(self.df).hasUniqueKey("_1").hasUniqueKey("_1", "_2")
            z = Mock()
            reporter = ZeppelinReporter(z)
            check.run([reporter])
            expected_output = """
%html
</p>
<h4>Checking [_1: bigint, _2: string]</h4>
<h5>It has a total number of 2 columns and 3 rows.</h5>
<table>
<tr><td style="padding:3px">&#10060;</td><td style="padding:3px">Column _1 is not a key (1 non-unique tuple).</td></tr>
<tr><td style="padding:3px">&#9989;</td><td style="padding:3px">Columns _1, _2 are a key.</td></tr>
</table>
<p hidden>
""".strip()
            self.assertEqual(baos.get_output(), expected_output)