Exemplo n.º 1
0
class TestPlots(unittest.TestCase):
    def setUp(self):
        data = {
            0: [
                "A", 0.000758130, 0.000696718, 0.000980080, 0.000988899,
                0.000875510, 0.000734843, 0.000754852, 0.000667378,
                0.000671230, 0.000790935
            ],
            1: [
                "B", 0.000758130, 0.000696718, 0.000980080, 0.000988899,
                0.000875510, 0.000734843, 0.000754852, 0.000667378,
                0.000671230, 0.000790935
            ]
        }
        timings = pd.DataFrame(data=data)
        mock_read_csv = mock.Mock(spec=pd.read_csv)
        mock_read_csv.return_value = timings.transpose()
        with mock.patch("tlsfuzzer.analysis.pd.read_csv", mock_read_csv):
            self.analysis = Analysis("/tmp")

    def test_qq_plot(self):
        with mock.patch("tlsfuzzer.analysis.plt.savefig",
                        mock.Mock()) as mock_save:
            self.analysis.qq_plot()
            mock_save.assert_called_once()

    def test_ecdf_plot(self):
        with mock.patch("tlsfuzzer.analysis.plt.savefig",
                        mock.Mock()) as mock_save:
            self.analysis.ecdf_plot()
            mock_save.assert_called_once()

    def test_scatter_plot(self):
        with mock.patch("tlsfuzzer.analysis.plt.savefig",
                        mock.Mock()) as mock_save:
            self.analysis.scatter_plot()
            mock_save.assert_called_once()

    def test_box_plot(self):
        with mock.patch("tlsfuzzer.analysis.plt.savefig",
                        mock.Mock()) as mock_save:
            self.analysis.box_plot()
            mock_save.assert_called_once()
Exemplo n.º 2
0
class TestPlots(unittest.TestCase):
    def setUp(self):
        data = {
            'A': [0.000758130, 0.000696718, 0.000980080, 0.000988899, 0.000875510,
                0.000734843, 0.000754852, 0.000667378, 0.000671230, 0.000790935],
            'B': [0.000758130, 0.000696718, 0.000980080, 0.000988899, 0.000875510,
                0.000734843, 0.000754852, 0.000667378, 0.000671230, 0.000790935]
        }
        timings = pd.DataFrame(data=data)
        mock_read_csv = mock.Mock(spec=pd.read_csv)
        mock_read_csv.return_value = timings
        with mock.patch("tlsfuzzer.analysis.pd.read_csv", mock_read_csv):
            self.analysis = Analysis("/tmp")

    def test_ecdf_plot(self):
        with mock.patch("tlsfuzzer.analysis.FigureCanvas.print_figure",
                        mock.Mock()) as mock_save:
            self.analysis.ecdf_plot()
            mock_save.assert_called_once()

    def test_scatter_plot(self):
        with mock.patch("tlsfuzzer.analysis.FigureCanvas.print_figure",
                        mock.Mock()) as mock_save:
            self.analysis.scatter_plot()
            mock_save.assert_called_once()

    def test_box_plot(self):
        with mock.patch("tlsfuzzer.analysis.FigureCanvas.print_figure",
                        mock.Mock()) as mock_save:
            self.analysis.box_plot()
            mock_save.assert_called_once()

    def test_conf_interval_plot(self):
        with mock.patch("tlsfuzzer.analysis.FigureCanvas.print_figure",
                        mock.Mock()) as mock_save:
            with mock.patch("__main__.__builtins__.open", mock.mock_open())\
                    as mock_open:
                self.analysis.conf_interval_plot()
                mock_save.assert_called_once()
class TestPlots(unittest.TestCase):
    def setUp(self):
        data = {
            'A': [
                0.000758130, 0.000696718, 0.000980080, 0.000988899,
                0.000875510, 0.000734843, 0.000754852, 0.000667378,
                0.000671230, 0.000790935
            ],
            'B': [
                0.000758130, 0.000696718, 0.000980080, 0.000988899,
                0.000875510, 0.000734843, 0.000754852, 0.000667378,
                0.000671230, 0.000790935
            ]
        }
        timings = pd.DataFrame(data=data)
        mock_read_csv = mock.Mock()
        mock_read_csv.return_value = timings
        with mock.patch("tlsfuzzer.analysis.Analysis.load_data",
                        mock_read_csv):
            self.analysis = Analysis("/tmp")
        self.analysis.load_data = mock_read_csv

    def test_ecdf_plot(self):
        with mock.patch("tlsfuzzer.analysis.FigureCanvas.print_figure",
                        mock.Mock()) as mock_save:
            self.analysis.ecdf_plot()
            self.assertEqual(mock_save.call_args_list, [
                mock.call('/tmp/ecdf_plot.png', bbox_inches='tight'),
                mock.call('/tmp/ecdf_plot_zoom_in.png', bbox_inches='tight')
            ])

    def test_diff_ecdf_plot(self):
        with mock.patch("tlsfuzzer.analysis.FigureCanvas.print_figure",
                        mock.Mock()) as mock_save:
            self.analysis.diff_ecdf_plot()
            self.assertEqual(mock_save.call_args_list, [
                mock.call('/tmp/diff_ecdf_plot.png', bbox_inches='tight'),
                mock.call('/tmp/diff_ecdf_plot_zoom_in_98.png',
                          bbox_inches='tight'),
                mock.call('/tmp/diff_ecdf_plot_zoom_in_33.png',
                          bbox_inches='tight'),
                mock.call('/tmp/diff_ecdf_plot_zoom_in_10.png',
                          bbox_inches='tight')
            ])

    def test_scatter_plot(self):
        with mock.patch("tlsfuzzer.analysis.FigureCanvas.print_figure",
                        mock.Mock()) as mock_save:
            self.analysis.scatter_plot()
            self.assertEqual(mock_save.call_args_list, [
                mock.call('/tmp/scatter_plot.png', bbox_inches='tight'),
                mock.call('/tmp/scatter_plot_zoom_in.png', bbox_inches='tight')
            ])

    def test_diff_scatter_plot(self):
        with mock.patch("tlsfuzzer.analysis.FigureCanvas.print_figure",
                        mock.Mock()) as mock_save:
            self.analysis.diff_scatter_plot()
            self.assertEqual(mock_save.call_args_list, [
                mock.call('/tmp/diff_scatter_plot.png', bbox_inches='tight'),
                mock.call('/tmp/diff_scatter_plot_zoom_in.png',
                          bbox_inches='tight')
            ])

    def test_box_plot(self):
        with mock.patch("tlsfuzzer.analysis.FigureCanvas.print_figure",
                        mock.Mock()) as mock_save:
            with mock.patch("tlsfuzzer.analysis.Analysis._calc_percentiles")\
                    as mock_percentiles:
                mock_percentiles.return_value = pd.DataFrame(
                    data={
                        'A': [0.05, 0.25, 0.5, 0.75, 0.95],
                        'B': [0.55, 0.75, 1, 1.25, 1.45]
                    })
                self.analysis.box_plot()
                mock_save.assert_called_once()
                mock_percentiles.assert_called_once_with()

    @mock.patch("tlsfuzzer.analysis.np.memmap")
    @mock.patch("tlsfuzzer.analysis.os.remove")
    @mock.patch("tlsfuzzer.analysis.shutil.copyfile")
    def test__calc_percentiles(self, mock_copyfile, mock_remove, mock_memmap):
        mock_memmap.return_value = self.analysis.load_data()

        ret = self.analysis._calc_percentiles()

        self.assertIsNotNone(ret)
        self.assertEqual(ret.values[0, 0], 0.0006691114)
        mock_copyfile.assert_called_once_with("/tmp/timing.bin",
                                              "/tmp/.quantiles.tmp")
        mock_remove.assert_called_once_with("/tmp/.quantiles.tmp")

    def test_conf_interval_plot(self):
        with mock.patch("tlsfuzzer.analysis.FigureCanvas.print_figure",
                        mock.Mock()) as mock_save:
            with mock.patch("__main__.__builtins__.open", mock.mock_open())\
                    as mock_open:
                self.analysis.conf_interval_plot()
                self.assertEqual(mock_save.call_args_list, [
                    mock.call('/tmp/conf_interval_plot_mean.png',
                              bbox_inches='tight'),
                    mock.call('/tmp/conf_interval_plot_median.png',
                              bbox_inches='tight'),
                    mock.call('/tmp/conf_interval_plot_trim_mean_05.png',
                              bbox_inches='tight'),
                    mock.call('/tmp/conf_interval_plot_trim_mean_25.png',
                              bbox_inches='tight'),
                    mock.call('/tmp/conf_interval_plot_trimean.png',
                              bbox_inches='tight')
                ])