9
9
10
10
# тестируемый метод draw_graph
11
11
from gui .mainwindow import MainWindow
12
+ from parameters import Parameters
12
13
13
14
14
15
class Closeable :
15
16
def close (self ):
16
17
print ('closed' )
17
18
18
19
19
- type_f = ["" , "method_min" , "hyperbolic_potential" , "exponential_potential" ]
20
- constraints = [[], [- 6 , 6 ]]
21
- params = [True , None ]
22
- # constraints = [[], [-6], [-6, 6], [6, -6], [0, 0], [-1, 0, 1]]
23
-
24
-
25
- @pytest .fixture (params = type_f )
26
- def param_type_f (request ):
27
- return request .param
28
-
29
-
30
- @pytest .fixture (params = constraints )
31
- def param_constraints (request ):
32
- return request .param
33
-
34
-
35
- @pytest .fixture (params = params )
36
- def param_loop (request ):
37
- return request .param
38
-
39
-
40
20
class TestDrawGraph :
41
- # @patch('gui.mainwindow.MainWindow.create_layout_with_graph')
42
- # @patch('gui.mainwindow.MainWindow.delete_widget')
43
- # @patch('gui.mainwindow.MainWindow.display_error_message')
44
- def setup (self ): # no_print_er, no_dw, no_create_graph
45
- # self.no_print_er = no_print_er
46
- # self.no_dw = no_dw
47
- # self.no_create_graph = no_create_graph
48
-
21
+ def setup (self ):
49
22
self .app = QApplication (sys .argv )
50
23
self .mw = MainWindow ()
51
24
self .mw .show ()
@@ -54,78 +27,46 @@ def teardown(self):
54
27
with pytest .raises (SystemExit ):
55
28
with contextlib .closing (Closeable ()):
56
29
sys .exit ()
57
- # sys.exit(self.app.exec_())
58
30
59
31
@patch ('graph.graph_3d.Canvas3dGraph' )
60
32
@patch ('graph.contour_graph.CanvasContourGraph' )
61
33
@patch ('graph.slice_graph.CanvasSliceGraph' )
62
34
@patch ('gui.mainwindow.MainWindow.create_layout_with_graph' )
63
35
@patch ('gui.mainwindow.MainWindow.delete_widget' )
64
- @patch ('gui.mainwindow.MainWindow.display_error_message' )
65
36
@patch ('gui.mainwindow.MainWindow.read_type' )
66
- @patch ('parser_field.parse_number_list' )
67
37
@patch ('gui.mainwindow.MainWindow.read_parameters_function' )
68
- @patch ('gui.mainwindow.MainWindow.get_func' )
69
- def test_draw_graph (self , no_func , no_rpf , no_parser_field , no_rt , no_print_er , no_dw , no_create_graph ,
70
- no_slice , no_contour , no_3d ,
71
- param_type_f , param_constraints , param_loop ):
72
- print (param_type_f )
73
- print (param_constraints )
74
-
75
- # замена возвращаемого функцией parser_field.parse_number_list значения
76
- no_parser_field .return_value = param_constraints
38
+ def test_draw_graph (self , read_parameters_function , no_rt , no_dw , no_create_graph ,
39
+ no_slice , no_contour , no_3d ):
77
40
78
41
# замена возвращаемого методом MainWindow.read_parameters_function значения
79
- no_rpf .return_value = param_loop
42
+ coord = [[- 2 , 4 ], [0 , 0 ], [4 , 4 ], [4 , 0 ], [- 2 , 0 ],[0 , - 2 ], [- 4 , 2 ], [2 , - 4 ], [2 , 2 ], [- 4 , - 2 ]]
43
+ func_value = [0 , 3 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 ]
44
+ p = Parameters (1 , "feldbaum_function" , 10 , coord , func_value ,
45
+ [[0.6 , 1.6 ], [1.6 , 2 ], [0.6 , 0.6 ], [1.1 , 1.8 ], [0.5 , 0.5 ], [1.3 , 1.3 ], [0.8 , 1.2 ], [0.9 , 0.3 ], [1.1 , 1.7 ], [1.2 , 0.5 ]],
46
+ [[6 , 6 ], [6 , 7 ], [6 , 7 ], [5 , 5 ], [5 , 5 ], [5 , 5 ], [4 , 3 ], [2 , 4 ], [6 , 4 ], [3 , 3 ]],
47
+ [6 , 6 ], [- 6 , - 6 ], [- 2 , 4 ], [6 , 6 ], min_f = 0 , max_f = 23 )
48
+ read_parameters_function .return_value = p
80
49
81
50
def f (): pass
82
- # def log(s): print(s)
83
51
84
52
no_dw .return_value = f
85
53
86
- no_rt .return_value = param_type_f
87
-
88
- no_func .return_value = f
54
+ no_rt .return_value = "feldbaum_function"
89
55
90
56
no_create_graph .return_value = f
91
57
92
58
self .mw .draw_graph ()
93
59
94
- assert no_rpf .called , "метод read_parameters_function не был вызван"
95
- assert no_parser_field .called , "функция parser_field.parse_number_list не была вызвана"
96
-
97
- if (not param_constraints ) or (param_loop is None ): # param_constraints == []
98
- no_print_er .assert_called_once_with ("Что-то пошло не так" )
99
- else :
100
- calls = [call (self .mw .ui .v_box_3d_graph ), call (self .mw .ui .v_box_contour_graph ),
101
- call (self .mw .ui .v_box_slice_graph1 ), call (self .mw .ui .v_box_slice_graph2 )]
102
- no_dw .assert_has_calls (calls )
103
-
104
- assert no_rt .called , "метод read_type не вызван"
105
- if param_type_f : # param_type_f != ""
106
- no_func .assert_called_once_with (param_type_f )
107
- no_create_graph .assert_called ()
108
- # assert no_3d in no_create_graph.call_args_list, "некорректный вызов метода create_layout_with_graph"
109
- no_create_graph .assert_called ()
110
- # assert no_contour in no_create_graph.call_args_list, "некорректный вызов метода create_layout_with_graph"
111
-
112
- # self.no_create_graph.assert_called()
113
- # assert no_slice in self.no_create_graph.call_args_list, "некорректный вызов метода create_layout_with_graph"
114
- # self.no_create_graph.assert_called()
115
- # assert no_slice in self.no_create_graph.call_args_list, "некорректный вызов метода create_layout_with_graph"
116
- else :
117
- no_print_er .assert_called_once_with ("Выберите метод конструирования тестовой функции" )
118
-
119
-
120
- # data = [('', {'uid': ['happy times']})]
121
- # search_s = Mock(return_value=data)
122
- # no_ldap.return_value = Mock(search_s=search_s)
123
- # count = 0
124
- # for i in find_users('', '', '', ''):
125
- # count += 1
126
- # assert i=='happy times'
127
- # assert count == 1
128
-
129
-
130
- # if __name__ == '__main__':
131
- # unittest.main(verbosity=2)
60
+ assert read_parameters_function .called , "метод read_parameters_function не был вызван"
61
+
62
+ calls = [call (self .mw .ui .v_box_3d_graph ), call (self .mw .ui .v_box_contour_graph ),
63
+ call (self .mw .ui .v_box_slice_graph1 ), call (self .mw .ui .v_box_slice_graph2 )]
64
+ no_dw .assert_has_calls (calls )
65
+
66
+ assert no_rt .called , "метод read_type не вызван"
67
+
68
+ for i in range (len (func_value )):
69
+ assert self .mw .func (coord [i ]) == func_value [i ]
70
+
71
+ no_create_graph .assert_called ()
72
+ no_create_graph .assert_called ()
0 commit comments