11import pytest
2+ import pandas as pd
23
34from pins .tests .helpers import DEFAULT_CREATION_DATE
45
6+ # using pytest cases, so that we can pass in fixtures as parameters
7+ from pytest_cases import fixture , parametrize
58
6- @pytest .fixture
9+
10+ @fixture
711def board (backend ):
812 yield backend .create_tmp_board ()
913 backend .teardown ()
1014
1115
16+ @fixture
17+ def df ():
18+ return pd .DataFrame ({"x" : [1 , 2 , 3 ], "y" : ["a" , "b" , "c" ]})
19+
20+
21+ # High level pins functionality -----------------------------------------------
22+
23+
1224def test_board_pin_write_default_title (board ):
13- import pandas as pd
1425
1526 df = pd .DataFrame ({"x" : [1 , 2 , 3 ], "y" : [4 , 5 , 6 ]})
1627 meta = board .pin_write (df , "df_csv" , title = None , type = "csv" )
1728 assert meta .title == "A pinned 3 x 2 CSV"
1829
1930
2031def test_board_pin_write_prepare_pin (board , tmp_dir2 ):
21- import pandas as pd
2232
2333 df = pd .DataFrame ({"x" : [1 , 2 , 3 ], "y" : [4 , 5 , 6 ]})
2434
@@ -32,7 +42,6 @@ def test_board_pin_write_prepare_pin(board, tmp_dir2):
3242
3343
3444def test_board_pin_write_roundtrip (board ):
35- import pandas as pd
3645
3746 df = pd .DataFrame ({"x" : [1 , 2 , 3 ], "y" : [4 , 5 , 6 ]})
3847
@@ -68,8 +77,6 @@ def test_board_pin_write_rsc_index_html(board, tmp_dir2, snapshot):
6877 if board .fs .protocol != "rsc" :
6978 pytest .skip ()
7079
71- import pandas as pd
72-
7380 df = pd .DataFrame ({"x" : [1 , 2 , 3 ], "y" : ["a" , "b" , "c" ]})
7481
7582 pin_name = "test_rsc_pin"
@@ -85,3 +92,21 @@ def test_board_pin_write_rsc_index_html(board, tmp_dir2, snapshot):
8592 )
8693
8794 snapshot .assert_equal_dir (tmp_dir2 )
95+
96+
97+ # pin_write against different types -------------------------------------------
98+
99+
100+ @parametrize (
101+ "obj, type_" , [(df , "csv" ), (df , "joblib" ), ({"a" : 1 , "b" : [2 , 3 ]}, "joblib" )]
102+ )
103+ def test_board_pin_write_type (board , obj , type_ , request ):
104+ meta = board .pin_write (obj , "test_pin" , type = type_ , title = "some title" )
105+ dst_obj = board .pin_read ("test_pin" )
106+
107+ assert meta .type == type_
108+
109+ if isinstance (obj , pd .DataFrame ):
110+ assert obj .equals (dst_obj )
111+
112+ obj == dst_obj
0 commit comments