11import pytest
22
3+
34@pytest .mark .parametrize (
45 "index" , [[1 , 2 ], [1.0 , 2.0 ], ["a" , "b" ], ["1" , "2" ], ["1." , "2." ]]
56)
67def test_param_one (index ):
78 def foo (x ):
89 print (type (x [0 ]))
9-
10+
1011 foo (index )
1112
13+
1214def test_no_params ():
1315 def none ():
1416 print ("none" )
1517
1618 none ()
17-
19+
20+
1821def some_callee ():
1922 return "some callee"
2023
24+
2125@pytest .fixture
2226def testparam ():
2327 return some_callee
2428
29+
2530def test_param_local (testparam ):
2631 print ("testparam is " + str (testparam ()))
27-
32+
33+
2834class TestTestClass :
2935 def show (self , x ):
3036 print (str (x ))
@@ -35,91 +41,118 @@ def test_param_two(self, value):
3541
3642
3743class notATestClass :
38-
3944 @pytest .mark .parametrize ("value" , [1 , "a" , True ])
4045 def test_param_three (self , value ):
4146 print (value )
4247
48+
4349@pytest .mark .parametrize (
4450 "index" , [[1 , 2 ], [1.0 , 2.0 ], ["a" , "b" ], ["1" , "2" ], ["1." , "2." ]]
4551)
46- @pytest .mark .parametrize (
47- "columns" , [["a" , "b" ], ["1" , "2" ], ["1." , "2." ]]
48- )
52+ @pytest .mark .parametrize ("columns" , [["a" , "b" ], ["1" , "2" ], ["1." , "2." ]])
4953def test_param_three (index , columns ):
5054 def f (x , y ):
5155 print ("(" + str (x ) + "," + str (y ) + ")" )
52-
56+
5357 for x in index :
5458 for y in columns :
5559 f (x , y )
5660
61+
5762import pandas_shim as pd
5863
64+
5965@pytest .mark .parametrize (
60- "name, expected_obj" ,[("pandas.isnull" , pd .isnull ), ("pandas.DataFrame" , pd .DataFrame )]
66+ "name, expected_obj" ,
67+ [("pandas.isnull" , pd .isnull ), ("pandas.DataFrame" , pd .DataFrame )],
6168)
6269def test_param_four (name , expected_obj ):
6370 print ("(" + str (name ) + "," + str (expected_obj (name )) + ")" )
6471
72+
6573@pytest .mark .parametrize (
66- "values" , [pd .Categorical ([]), pd .Categorical ([]).dtype , pd .Series (pd .Categorical ([]))]
74+ "values" ,
75+ [pd .Categorical ([]), pd .Categorical ([]).dtype , pd .Series (pd .Categorical ([]))],
6776)
6877def test_param_five (values ):
6978 def f (x ):
7079 print (str (x ))
71-
80+
7281 f (values )
73-
82+
83+
7484@pytest .mark .parametrize ("ascending" , [True , False ])
7585def test_param_six (ascending ):
7686 def f (x ):
7787 print (str (x ))
7888
7989 f (ascending )
80-
90+
91+
8192@pytest .mark .parametrize ("box" , [pd .Series , lambda x : x ])
8293def test_box (box ):
8394 def f (x ):
8495 print (str (x (0 )))
8596
8697 f (box )
87-
98+
99+
88100@pytest .mark .parametrize ("repeats" , [0 , 1 , 2 , [1 , 2 , 3 ]])
89101def test_repeat (repeats ):
90102 def f (x ):
91103 print (str (x ))
92104
93105 f (repeats )
94106
107+
95108from pandas_shim import DecimalArrayWithoutFromSequence , DecimalArrayWithoutCoercion
96109
97- @pytest .mark .parametrize ("class_" , [DecimalArrayWithoutFromSequence , DecimalArrayWithoutCoercion ])
110+
111+ @pytest .mark .parametrize (
112+ "class_" , [DecimalArrayWithoutFromSequence , DecimalArrayWithoutCoercion ]
113+ )
98114def test_class (class_ ):
99- print (class_ ().foo ())
115+ print (class_ ().foo ())
116+
100117
101- @pytest .mark .parametrize ("columns" ,[["A" , "B" ], pd .MultiIndex .from_tuples ([("A" , "a" ), ("A" , "b" )], names = ["outer" , "inner" ])])
118+ @pytest .mark .parametrize (
119+ "columns" ,
120+ [
121+ ["A" , "B" ],
122+ pd .MultiIndex .from_tuples ([("A" , "a" ), ("A" , "b" )], names = ["outer" , "inner" ]),
123+ ],
124+ )
102125def test_cols (columns ):
103- print ("(" + str (columns ) + ")" )
126+ print ("(" + str (columns ) + ")" )
127+
104128
105- #@pytest.mark.parametrize("repeats, kwargs, error, msg",[
106- #(2, dict(axis=1), ValueError, "'axis"),
107- #(-1, dict(), ValueError, "negative"),
108- #([1, 2], dict(), ValueError, "shape")])
109- #def test_dict(repeats, kwargs, error, msg):
129+ # @pytest.mark.parametrize("repeats, kwargs, error, msg",[
130+ # (2, dict(axis=1), ValueError, "'axis"),
131+ # (-1, dict(), ValueError, "negative"),
132+ # ([1, 2], dict(), ValueError, "shape")])
133+ # def test_dict(repeats, kwargs, error, msg):
110134# print("(" + str(repeats) + " " + str(kwargs) + " " + str(error) + " " + msg + ")")
111135
112136from pandas_shim import DataFrame
113137import np_shim as np
114138
115- @pytest .mark .parametrize ("header,expected" ,[(None , DataFrame ([0 ] + [np .nan ] * 4 )), (0 , DataFrame ([np .nan ] * 4 ))])
139+
140+ @pytest .mark .parametrize (
141+ "header,expected" ,
142+ [(None , DataFrame ([0 ] + [np .nan ] * 4 )), (0 , DataFrame ([np .nan ] * 4 ))],
143+ )
116144def test_head_expected (header , expected ):
117- print ("(" + str (header ) + " " + str (expected ))
145+ print ("(" + str (header ) + " " + str (expected ))
118146
119147
120- @pytest .mark .parametrize ("option,result,expected" ,[ (None , lambda df : df .to_html (), "1" ), (None , lambda df : df .to_html (border = 0 ), "0" ), (0 , lambda df : df .to_html (), "0" )])
148+ @pytest .mark .parametrize (
149+ "option,result,expected" ,
150+ [
151+ (None , lambda df : df .to_html (), "1" ),
152+ (None , lambda df : df .to_html (border = 0 ), "0" ),
153+ (0 , lambda df : df .to_html (), "0" ),
154+ ],
155+ )
121156def test_lamda_call (option , result , expected ):
122157 df = DataFrame ({"A" : [1 , 2 ]})
123158 print ("(" + str (option ) + " " + str (result (df )) + " " + str (expected ))
124-
125-
0 commit comments