66import numpy as np
77import pandas as pd
88import pytest
9+ from databento .common .constants import ALL_SYMBOLS
910from databento .common .parsing import optional_date_to_string
1011from databento .common .parsing import optional_datetime_to_string
1112from databento .common .parsing import optional_datetime_to_unix_nanoseconds
1213from databento .common .parsing import optional_symbols_list_to_list
1314from databento .common .parsing import optional_values_list_to_string
15+ from databento .common .parsing import symbols_list_to_list
1416from databento_dbn import SType
1517
1618
@@ -50,7 +52,9 @@ def test_maybe_values_list_to_string_given_valid_inputs_returns_expected(
5052@pytest .mark .parametrize (
5153 "stype, symbols, expected" ,
5254 [
53- pytest .param (SType .RAW_SYMBOL , None , ["ALL_SYMBOLS" ]),
55+ pytest .param (SType .RAW_SYMBOL , None , TypeError ),
56+ pytest .param (SType .PARENT , ["ES" , None ], TypeError ),
57+ pytest .param (SType .PARENT , ["ES" , [None ]], TypeError ),
5458 pytest .param (SType .PARENT , "ES.fut" , ["ES.FUT" ]),
5559 pytest .param (SType .PARENT , "ES,CL" , ["ES" , "CL" ]),
5660 pytest .param (SType .PARENT , "ES,CL," , ["ES" , "CL" ]),
@@ -67,22 +71,24 @@ def test_maybe_values_list_to_string_given_valid_inputs_returns_expected(
6771 pytest .param (SType .PARENT , 123458 , ValueError ),
6872 ],
6973)
70- def test_optional_symbols_list_to_list_given_valid_inputs_returns_expected (
74+ def test_symbols_list_to_list_given_valid_inputs_returns_expected (
7175 stype : SType ,
7276 symbols : list [str ] | None ,
7377 expected : list [object ] | type [Exception ],
7478) -> None :
7579 # Arrange, Act, Assert
7680 if isinstance (expected , list ):
77- assert optional_symbols_list_to_list (symbols , stype ) == expected
81+ assert symbols_list_to_list (symbols , stype ) == expected
7882 else :
7983 with pytest .raises (expected ):
80- optional_symbols_list_to_list (symbols , stype )
84+ symbols_list_to_list (symbols , stype )
8185
8286
8387@pytest .mark .parametrize (
8488 "symbols, stype, expected" ,
8589 [
90+ pytest .param ([12345 , None ], SType .INSTRUMENT_ID , TypeError ),
91+ pytest .param ([12345 , [None ]], SType .INSTRUMENT_ID , TypeError ),
8692 pytest .param (12345 , SType .INSTRUMENT_ID , ["12345" ]),
8793 pytest .param ("67890" , SType .INSTRUMENT_ID , ["67890" ]),
8894 pytest .param ([12345 , " 67890" ], SType .INSTRUMENT_ID , ["12345" , "67890" ]),
@@ -104,7 +110,7 @@ def test_optional_symbols_list_to_list_given_valid_inputs_returns_expected(
104110 pytest .param (12345 , SType .CONTINUOUS , ValueError ),
105111 ],
106112)
107- def test_optional_symbols_list_to_list_int (
113+ def test_symbols_list_to_list_int (
108114 symbols : list [int ] | int | None ,
109115 stype : SType ,
110116 expected : list [object ] | type [Exception ],
@@ -117,15 +123,18 @@ def test_optional_symbols_list_to_list_int(
117123 """
118124 # Arrange, Act, Assert
119125 if isinstance (expected , list ):
120- assert optional_symbols_list_to_list (symbols , stype ) == expected
126+ assert symbols_list_to_list (symbols , stype ) == expected
121127 else :
122128 with pytest .raises (expected ):
123- optional_symbols_list_to_list (symbols , stype )
129+ symbols_list_to_list (symbols , stype )
124130
125131
126132@pytest .mark .parametrize (
127133 "symbols, stype, expected" ,
128134 [
135+ pytest .param (None , SType .INSTRUMENT_ID , TypeError ),
136+ pytest .param ([np .byte (120 ), None ], SType .INSTRUMENT_ID , TypeError ),
137+ pytest .param ([np .byte (120 ), [None ]], SType .INSTRUMENT_ID , TypeError ),
129138 pytest .param (np .byte (120 ), SType .INSTRUMENT_ID , ["120" ]),
130139 pytest .param (np .short (32_000 ), SType .INSTRUMENT_ID , ["32000" ]),
131140 pytest .param (
@@ -140,7 +149,7 @@ def test_optional_symbols_list_to_list_int(
140149 ),
141150 ],
142151)
143- def test_optional_symbols_list_to_list_numpy (
152+ def test_symbols_list_to_list_numpy (
144153 symbols : list [int ] | int | None ,
145154 stype : SType ,
146155 expected : list [object ] | type [Exception ],
@@ -153,15 +162,18 @@ def test_optional_symbols_list_to_list_numpy(
153162 """
154163 # Arrange, Act, Assert
155164 if isinstance (expected , list ):
156- assert optional_symbols_list_to_list (symbols , stype ) == expected
165+ assert symbols_list_to_list (symbols , stype ) == expected
157166 else :
158167 with pytest .raises (expected ):
159- optional_symbols_list_to_list (symbols , stype )
168+ symbols_list_to_list (symbols , stype )
160169
161170
162171@pytest .mark .parametrize (
163172 "symbols, stype, expected" ,
164173 [
174+ pytest .param (None , SType .RAW_SYMBOL , TypeError ),
175+ pytest .param (["NVDA" , None ], SType .RAW_SYMBOL , TypeError ),
176+ pytest .param (["NVDA" , [None ]], SType .RAW_SYMBOL , TypeError ),
165177 pytest .param ("NVDA" , SType .RAW_SYMBOL , ["NVDA" ]),
166178 pytest .param (" nvda " , SType .RAW_SYMBOL , ["NVDA" ]),
167179 pytest .param ("NVDA,amd" , SType .RAW_SYMBOL , ["NVDA" , "AMD" ]),
@@ -179,7 +191,7 @@ def test_optional_symbols_list_to_list_numpy(
179191 pytest .param (["NVDA" , ["" ]], SType .RAW_SYMBOL , ValueError ),
180192 ],
181193)
182- def test_optional_symbols_list_to_list_raw_symbol (
194+ def test_symbols_list_to_list_raw_symbol (
183195 symbols : list [int ] | int | None ,
184196 stype : SType ,
185197 expected : list [object ] | type [Exception ],
@@ -188,6 +200,35 @@ def test_optional_symbols_list_to_list_raw_symbol(
188200 Test that str are allowed for SType.RAW_SYMBOL.
189201 """
190202 # Arrange, Act, Assert
203+ if isinstance (expected , list ):
204+ assert symbols_list_to_list (symbols , stype ) == expected
205+ else :
206+ with pytest .raises (expected ):
207+ symbols_list_to_list (symbols , stype )
208+
209+
210+ @pytest .mark .parametrize (
211+ "symbols, stype, expected" ,
212+ [
213+ pytest .param (None , SType .RAW_SYMBOL , [ALL_SYMBOLS ]),
214+ pytest .param (["NVDA" , None ], SType .RAW_SYMBOL , TypeError ),
215+ pytest .param ([12345 , None ], SType .INSTRUMENT_ID , TypeError ),
216+ pytest .param ("NVDA" , SType .RAW_SYMBOL , ["NVDA" ]),
217+ pytest .param (["NVDA" , "TSLA" ], SType .RAW_SYMBOL , ["NVDA" , "TSLA" ]),
218+ pytest .param (12345 , SType .INSTRUMENT_ID , ["12345" ]),
219+ pytest .param ([12345 , "67890" ], SType .INSTRUMENT_ID , ["12345" , "67890" ]),
220+ ],
221+ )
222+ def test_optional_symbols_list_to_list_raw_symbol (
223+ symbols : list [int | str ] | int | str | None ,
224+ stype : SType ,
225+ expected : list [object ] | type [Exception ],
226+ ) -> None :
227+ """
228+ Test an optional symbols list converts a value of `None` to `[ALL_SYMBOLS]`
229+ and handles other symbols lists.
230+ """
231+ # Arrange, Act, Assert
191232 if isinstance (expected , list ):
192233 assert optional_symbols_list_to_list (symbols , stype ) == expected
193234 else :
0 commit comments