|
1 | 1 | import contextlib |
| 2 | +import functools |
2 | 3 | import json |
3 | 4 | import os |
4 | 5 | import shutil |
|
21 | 22 | # TODO: should use pkg_resources for this path? |
22 | 23 | RSC_KEYS_FNAME = "pins/tests/rsconnect_api_keys.json" |
23 | 24 |
|
| 25 | +DATABRICKS_VOLUME = "/Volumes/workshops/my-board/my-volume/test" |
| 26 | + |
24 | 27 | BOARD_CONFIG = { |
25 | 28 | "file": {"path": ["PINS_TEST_FILE__PATH", None]}, |
26 | 29 | "s3": {"path": ["PINS_TEST_S3__PATH", "ci-pins"]}, |
27 | 30 | "gcs": {"path": ["PINS_TEST_GCS__PATH", "pins-python"]}, |
28 | 31 | "abfs": {"path": ["PINS_TEST_AZURE__PATH", "ci-pins"]}, |
29 | 32 | "rsc": {"path": ["PINS_TEST_RSC__PATH", RSC_SERVER_URL]}, |
30 | | - "dbc": {"path": ["PINS_TEST_DBC__PATH", "DATABRICKS_VOLUME"]}, |
| 33 | + "dbc": {"path": ["PINS_TEST_DBC__PATH", DATABRICKS_VOLUME]}, |
31 | 34 | } |
32 | 35 |
|
33 | 36 | # TODO: Backend initialization should be independent of helpers, but these |
34 | 37 | # high-level initializers are super handy. |
35 | 38 | # putting imports inside rsconnect particulars for now |
36 | 39 |
|
37 | 40 |
|
| 41 | +def skip_if_dbc(func): |
| 42 | + """Decorator to skip test if board protocol is 'dbc'""" |
| 43 | + @functools.wraps(func) |
| 44 | + def wrapper(*args, **kwargs): |
| 45 | + import inspect |
| 46 | + board = None |
| 47 | + |
| 48 | + # Get function signature to map args to parameter names. |
| 49 | + # We have to do this since parameterized pytest runs passes in |
| 50 | + # args in different orders |
| 51 | + sig = inspect.signature(func) |
| 52 | + bound_args = sig.bind_partial(*args, **kwargs) |
| 53 | + all_args = {**bound_args.arguments, **kwargs} |
| 54 | + |
| 55 | + if 'board' in all_args: |
| 56 | + board = all_args['board'] |
| 57 | + elif 'board_with_cache' in all_args: |
| 58 | + board = all_args['board_with_cache'] |
| 59 | + else: |
| 60 | + # Check all arguments for something that looks like a board |
| 61 | + for arg_value in all_args.values(): |
| 62 | + if hasattr(arg_value, 'fs') and hasattr(arg_value.fs, 'protocol'): |
| 63 | + board = arg_value |
| 64 | + break |
| 65 | + |
| 66 | + if board and board.fs.protocol == "dbc": |
| 67 | + pytest.skip("All Databricks tests must be read only") |
| 68 | + |
| 69 | + return func(*args, **kwargs) |
| 70 | + return wrapper |
| 71 | + |
| 72 | + |
38 | 73 | def rsc_from_key(name): |
39 | 74 | from pins.rsconnect.api import RsConnectApi |
40 | 75 |
|
@@ -209,24 +244,32 @@ def __init__(self, fs_name, path=None, *args, **kwargs): |
209 | 244 | self.path = None |
210 | 245 | self.fs_name = fs_name |
211 | 246 | self.current_board = None |
212 | | - self.volume = os.environ.get("DATABRICKS_VOLUME") |
| 247 | + self.volume = DATABRICKS_VOLUME |
213 | 248 |
|
214 | 249 | def create_tmp_board(self, src_board=None, versioned=True): |
215 | | - temp_name = str(uuid.uuid4()) |
216 | | - board_name = os.path.join(self.volume, temp_name) |
217 | | - db_board = board_databricks(board_name, cache=None) |
218 | | - board = BaseBoard(board_name, fs=db_board.fs, versioned=versioned) |
| 250 | + # TODO: use temp boards when boards are not read-only |
| 251 | + # temp_name = str(uuid.uuid4()) |
| 252 | + # board_name = os.path.join(self.volume, temp_name) |
| 253 | + # db_board = board_databricks(board_name, cache=None) |
| 254 | + # board = BaseBoard(board_name, fs=db_board.fs, versioned=versioned) |
| 255 | + # if src_board is not None: |
| 256 | + # board.fs.put(src_board, board_name) |
| 257 | + |
| 258 | + db_board = board_databricks(self.volume, cache=None) |
| 259 | + board = BaseBoard(self.volume, fs=db_board.fs, versioned=versioned) |
219 | 260 | self.current_board = board |
220 | | - if src_board is not None: |
221 | | - board.fs.put(src_board, board_name) |
222 | 261 | return board |
223 | 262 |
|
224 | 263 | def teardown_board(self, board): |
225 | | - board.fs.rm(board.board) |
| 264 | + pass |
| 265 | + # TODO: update when board not read-only |
| 266 | + # board.fs.rm(board.board) |
226 | 267 |
|
227 | 268 | def teardown(self): |
228 | | - board = board_databricks(self.volume) |
229 | | - board.fs.rm(self.current_board.board) |
| 269 | + pass |
| 270 | + # TODO: update when board not read-only |
| 271 | + # board = board_databricks(self.volume) |
| 272 | + # board.fs.rm(self.current_board.board) |
230 | 273 |
|
231 | 274 |
|
232 | 275 | # Snapshot ==================================================================== |
|
0 commit comments