def test_first(self):
     with patch(patch_name(module_name, "plt.show")) as pshow,\
          patch(patch_name(module_name, "plt.plot")) as pplot,\
          patch(patch_name(module_name, "plt.xlabel")) as pxlabel,\
          patch(patch_name(module_name, "plt.ylabel")) as pylabel:
         main()
         pshow.assert_called_once()
         pxlabel.assert_called_once()
         pylabel.assert_called_once()
         self.assertGreater(pplot.call_count,
                            0,
                            msg="You should have called plt.plot!")
         self.assertLess(
             pplot.call_count,
             3,
             msg="You should have called plt.plot at most two times!")
         if pplot.call_count == 2:
             np.testing.assert_array_equal(
                 pplot.call_args_list[0][0][0], [2, 4, 6, 7],
                 err_msg="Wrong parameters to plot!")
             np.testing.assert_array_equal(
                 pplot.call_args_list[0][0][1], [4, 3, 5, 1],
                 err_msg="Wrong parameters to plot!")
             np.testing.assert_array_equal(
                 pplot.call_args_list[1][0][0], [1, 2, 3, 4],
                 err_msg="Wrong parameters to plot!")
             np.testing.assert_array_equal(
                 pplot.call_args_list[1][0][1], [4, 2, 3, 1],
                 err_msg="Wrong parameters to plot!")
         else:
             np.testing.assert_array_equal(
                 pplot.call_args_list[0][0],
                 ([2, 4, 6, 7], [4, 3, 5, 1], [1, 2, 3, 4], [4, 2, 3, 1]),
                 err_msg="Parameters to the plt.plot command were wrong")
 def test_main(self):
     with patch(patch_name(module_name, "create_series"), wraps=create_series) as pcs,\
          patch(patch_name(module_name, "pd.Series.__add__"), side_effect=[pd.Series()]) as padd,\
          patch(patch_name(module_name, "modify_series"), wraps=modify_series) as pms:
         main()
         pcs.assert_called()
         pms.assert_called()
         padd.assert_called()
 def test_called(self):
     with patch('builtins.open', side_effect=open) as o,\
          patch(patch_name(module_name, 're.match'), side_effect=re.match) as m,\
          patch(patch_name(module_name, 're.search'), side_effect=re.search) as s,\
          patch(patch_name(module_name, 're.findall'), side_effect=re.findall) as fa,\
          patch(patch_name(module_name, 're.finditer'), side_effect=re.finditer) as fi:
         result=red_green_blue()
         o.assert_called()
         self.assertTrue(m.called or s.called or fa.called or fi.called)
 def test_main(self):
     with patch(patch_name(module_name, "plt.show")) as pshow:
         with patch(patch_name(module_name, "plt.imshow"),
                    side_effect=plt.imshow) as pimshow:
             with patch(patch_name(module_name, "plt.subplots"),
                        side_effect=plt.subplots) as psubplots:
                 main()
                 pshow.assert_called()
                 pimshow.assert_called()
                 psubplots.assert_called_once()
 def test_main(self):
     with patch(patch_name(module_name, "plt.subplots"), side_effect=plt.subplots) as psubplots,\
          patch(patch_name(module_name, "radial_mask"), side_effect=radial_mask) as pradial_mask,\
          patch(patch_name(module_name, "radial_fade"), side_effect=radial_mask) as pradial_fade,\
          patch(patch_name(module_name, "plt.show")) as pshow:
         main()
         psubplots.assert_called_once()
         pshow.assert_called()
         pradial_mask.assert_called()
         pradial_fade.assert_called()
    def test_calls(self):
        n = 10
        a = np.random.randint(0, 10, (n, 3))
        a = np.concatenate([np.arange(n)[:, np.newaxis], a], axis=1)

        with patch(patch_name(module_name, "plt.show")) as pshow:
            with patch(patch_name(module_name, "plt.subplots"), side_effect=plt.subplots) as psubplots:
                subfigures(a)
                pshow.assert_called_once()
                psubplots.assert_called_once()
                self.assertEqual(psubplots.call_args[0][:2], (1,2), msg="Wrong shape of subplot grid")
 def test_called(self):
     with patch('builtins.open', side_effect=open) as o,\
          patch(patch_name(module_name, 're.compile'), side_effect=re.compile) as c,\
          patch(patch_name(module_name, 're.match'), side_effect=re.match) as m,\
          patch(patch_name(module_name, 're.search'), side_effect=re.search) as s,\
          patch(patch_name(module_name, 're.findall'), side_effect=re.findall) as fa,\
          patch(patch_name(module_name, 're.finditer'), side_effect=re.finditer) as fi:
         result=file_listing()
         o.assert_called()
         self.assertTrue(c.called or m.called or s.called or fa.called or fi.called,
                         msg="Expected that one of the following was called: "
                         "re.search, re.findall, re.finditer!")
 def test_calls(self):
     with patch(patch_name(module_name, "np.linalg.lstsq"),
                side_effect=np.linalg.lstsq) as psolve:
         a1 = 1
         b1 = 4
         a2 = 3
         b2 = 2
         almost_meeting_lines(a1, b1, a2, b2)
         psolve.assert_called()
Ejemplo n.º 9
0
 def test_calls(self):
     with patch(patch_name(module_name, "np.linalg.solve"),
                wraps=np.linalg.solve) as psolve:
         a1 = 1
         b1 = 4
         a2 = 3
         b2 = 2
         meeting_lines(a1, b1, a2, b2)
         psolve.assert_called()
    def test_method_calls(self):
        n = 10
        a = np.random.randint(0, 10, (n, 3))
        a = np.concatenate([np.arange(n)[:, np.newaxis], a], axis=1)

        mysub = MockSubplots()
        with patch(patch_name(module_name, "plt.show")) as pshow:
            with patch(patch_name(module_name, "plt.subplots"), side_effect=mysub) as psubplots:
                subfigures(a)
                pshow.assert_called_once()
                psubplots.assert_called_once()
                self.assertEqual(psubplots.call_args[0][:2], (1,2), msg="Wrong shape of subplot grid")
                mysub.ax[0].plot.assert_called_once()
                mysub.ax[1].scatter.assert_called_once()
                np.testing.assert_array_equal(mysub.ax[0].plot.call_args[0][0], a[:,0])
                np.testing.assert_array_equal(mysub.ax[0].plot.call_args[0][1], a[:,1])
                positional = mysub.ax[1].scatter.call_args[0]
                kwargs = mysub.ax[1].scatter.call_args[1]
                if len(positional) >= 2:
                    np.testing.assert_array_equal(positional[0], a[:,0],
                                                  err_msg="x-coordinates were not correct for scatter call!")
                    np.testing.assert_array_equal(positional[1], a[:,1],
                                                  err_msg="y-coordinates were not correct for scatter call!")
                elif "x" in kwargs and "y" in kwargs:
                    np.testing.assert_array_equal(kwargs["x"], a[:,0],
                                                  err_msg="x-coordinates were not correct for scatter call!")
                    np.testing.assert_array_equal(kwargs["y"], a[:,1],
                                                  err_msg="y-coordinates were not correct for scatter call!")
                else:
                    self.assertTrue(False, msg="Give x and y for scatter call as position "
                                    "either as positional arguments or as keyword arguments!")

                self.assertIn("c", kwargs, msg="Give the 'c' keyword argument to scatter method call!")
                np.testing.assert_array_equal(kwargs["c"], a[:,2],
                                              err_msg="You did not give correct values to the 'c' parameter of the scatter function")
                self.assertIn("s", kwargs, msg="Give the 's' keyword argument to scatter method call!")
                np.testing.assert_array_equal(kwargs["s"], a[:,3],
                                              err_msg="You did not give correct values to the 's' parameter of the scatter function")
    def test_calls(self):
        a1 = 1
        b1 = 4
        c1 = 5

        a2 = 3
        b2 = 2
        c2 = 1

        a3 = 2
        b3 = 4
        c3 = 1

        with patch(patch_name(module_name, "np.linalg.solve"),
                   wraps=np.linalg.solve) as psolve:
            meeting_planes(a1, b1, c1, a2, b2, c2, a3, b3, c3)
            psolve.assert_called_once()
 def test_creation(self):
     self.assertEqual("", "")
     L1 = [2, 3, 4]
     L2 = [9, 8, 7]
     indices = list("abc")
     #        with patch(patch_name(module_name, "pd.core.series.Series"), wraps=pd.core.series.Series) as ps:
     with patch(patch_name(module_name, "pd.Series"),
                wraps=pd.Series) as ps:
         ret = create_series(L1, L2)
         self.assertEqual(
             len(ret),
             2,
             msg=
             "Expected a pair of Series as a return value from function create_series!"
         )
         s1, s2 = ret
         #ps.assert_called()
         self.assertEqual(
             ps.call_count,
             2,
             msg=
             "Expected the constructor pd.Series to be called exactly twice!"
         )
     np.testing.assert_array_equal(
         s1.values,
         L1,
         err_msg="Expected values of first series to be %s" % L1)
     np.testing.assert_array_equal(
         s2.values,
         L2,
         err_msg="Expected values of second series to be %s" % L2)
     np.testing.assert_array_equal(
         s1.index,
         indices,
         err_msg="Expected the index of first series to be %s" % indices)
     np.testing.assert_array_equal(
         s2.index,
         indices,
         err_msg="Expected the index of second series to be %s" % indices)
 def test_called(self):
     with patch(patch_name(module_name, "inverse_series"),
                wrap=inverse_series) as pis:
         main()
         pis.assert_called()
 def test_main(self):
     with patch(patch_name(module_name, "vector_angles"), wraps=vector_angles) as va:
         main()
     self.assertGreaterEqual(va.call_count, 1,
                             msg="You should call the vector_angles function from the main function!")
Ejemplo n.º 15
0
 def test_called(self):
     with patch(patch_name(module_name, "powers_of_series"),
                wraps=powers_of_series) as ppos:
         main()
         ppos.assert_called()