15
15
import pytest
16
16
import pandas as pd
17
17
18
+ import utils
18
19
import reset_tests
19
20
from fise .query import QueryHandler
20
21
25
26
TEST_RECORDS_FILE = Path (__file__ ).parent / "test_delete_query.hdf"
26
27
27
28
28
- def read_hdf (file : Path , path : str ) -> pd .Series :
29
- """
30
- Reads the test records stored at the specified
31
- path from the specified HDF5 file.
32
- """
33
-
34
- with pd .HDFStore (str (file )) as store :
35
- return store [path ]
36
-
37
-
38
29
# Pandas series comprising path of all the filses and directories
39
30
# present within the `file_dir` directory within the test directory.
40
31
FILE_DIR_TEST_DIRECTORY_LISTINGS = pd .concat (
41
32
[
42
- read_hdf (TEST_DIRECTORY_LISTINGS_FILE , "/file_dir/dirs" ),
43
- read_hdf (TEST_DIRECTORY_LISTINGS_FILE , "/file_dir/files" ),
33
+ utils . read_hdf (TEST_DIRECTORY_LISTINGS_FILE , "/file_dir/dirs" ),
34
+ utils . read_hdf (TEST_DIRECTORY_LISTINGS_FILE , "/file_dir/files" ),
44
35
],
45
36
ignore_index = True ,
46
37
)
@@ -55,7 +46,7 @@ def verify_delete_query(path: str) -> None:
55
46
56
47
# File and directories to be exempted during verification as
57
48
# they are meant to be removed during the delete operation.
58
- records : pd .Series = read_hdf (TEST_RECORDS_FILE , path )
49
+ records : pd .Series = utils . read_hdf (TEST_RECORDS_FILE , path )
59
50
60
51
for i in FILE_DIR_TEST_DIRECTORY_LISTINGS :
61
52
if (FILE_DIR_TEST_DIRECTORY / i ).exists () or i in records .values :
@@ -90,45 +81,75 @@ class TestFileDeleteQuery:
90
81
91
82
basic_query_syntax_test_params = [
92
83
(1 , f"DELETE FROM '{ FILE_DIR_TEST_DIRECTORY / 'project' } '" ),
93
- (2 , f"DELETE[TYPE FILE] FROM '{ FILE_DIR_TEST_DIRECTORY / 'media' } ' WHERE type = '.mp3'" ),
94
- (3 , rf"R DELETE FROM '{ FILE_DIR_TEST_DIRECTORY / 'project' } ' WHERE name LIKE '.*\.py'" ),
84
+ (
85
+ 2 ,
86
+ f"DELETE[TYPE FILE] FROM '{ FILE_DIR_TEST_DIRECTORY / 'media' } ' WHERE type = '.mp3'" ,
87
+ ),
88
+ (
89
+ 3 ,
90
+ rf"R DELETE FROM '{ FILE_DIR_TEST_DIRECTORY / 'project' } ' WHERE name LIKE '.*\.py'" ,
91
+ ),
95
92
]
96
93
97
94
recursive_command_test_params = [
98
- (1 , f"R DELETE FROM '{ FILE_DIR_TEST_DIRECTORY / 'reports' } ' WHERE name = 'Q4.txt'" ),
95
+ (
96
+ 1 ,
97
+ f"R DELETE FROM '{ FILE_DIR_TEST_DIRECTORY / 'reports' } ' WHERE name = 'Q4.txt'" ,
98
+ ),
99
99
(2 , f"RECURSIVE DELETE FROM '{ FILE_DIR_TEST_DIRECTORY / 'docs' } '" ),
100
100
]
101
101
102
102
path_types_test_params = [
103
- (1 , f"R DELETE FROM ABSOLUTE '{ FILE_DIR_TEST_DIRECTORY / 'reports' } ' WHERE name = 'Q2.txt'" ),
103
+ (
104
+ 1 ,
105
+ f"R DELETE FROM ABSOLUTE '{ FILE_DIR_TEST_DIRECTORY / 'reports' } ' WHERE name = 'Q2.txt'" ,
106
+ ),
104
107
(2 , f"DELETE FROM ABSOLUTE '{ FILE_DIR_TEST_DIRECTORY / 'project' } '" ),
105
- (3 , f"DELETE FROM RELATIVE '{ FILE_DIR_TEST_DIRECTORY / 'media' } ' WHERE type = '.mp4'" ),
108
+ (
109
+ 3 ,
110
+ f"DELETE FROM RELATIVE '{ FILE_DIR_TEST_DIRECTORY / 'media' } ' WHERE type = '.mp4'" ,
111
+ ),
106
112
]
107
113
108
114
mixed_case_query_test_params = [
109
115
(1 , f"DeLeTE FRoM '{ FILE_DIR_TEST_DIRECTORY / 'project' } '" ),
110
- (2 , f"DelETE[TYPE FiLE] FrOM '{ FILE_DIR_TEST_DIRECTORY / 'media' } ' Where TypE = '.mp3'" ),
111
- (3 , rf"r dELETe FrOM '{ FILE_DIR_TEST_DIRECTORY / 'project' } ' wHERe NaMe liKe '.*\.py'" ),
116
+ (
117
+ 2 ,
118
+ f"DelETE[TYPE FiLE] FrOM '{ FILE_DIR_TEST_DIRECTORY / 'media' } ' Where TypE = '.mp3'" ,
119
+ ),
120
+ (
121
+ 3 ,
122
+ rf"r dELETe FrOM '{ FILE_DIR_TEST_DIRECTORY / 'project' } ' wHERe NaMe liKe '.*\.py'" ,
123
+ ),
112
124
]
113
125
114
126
query_conditions_test_params = [
115
127
(1 , f"R DELETE FROM '{ FILE_DIR_TEST_DIRECTORY } ' WHERE name = 'Q1.txt'" ),
116
- (2 , rf"R DELETE FROM '{ FILE_DIR_TEST_DIRECTORY } ' WHERE type='.txt' AND name LIKE '^IN.*\.txt$'" ),
117
- (3 , f"R DELETE FROM '{ FILE_DIR_TEST_DIRECTORY } ' WHERE type IN ('.mp4', '.avi') OR type='.mp3'" ),
128
+ (
129
+ 2 ,
130
+ rf"R DELETE FROM '{ FILE_DIR_TEST_DIRECTORY } ' WHERE type='.txt' AND name LIKE '^IN.*\.txt$'" ,
131
+ ),
132
+ (
133
+ 3 ,
134
+ f"R DELETE FROM '{ FILE_DIR_TEST_DIRECTORY } ' WHERE type IN ('.mp4', '.avi') OR type='.mp3'" ,
135
+ ),
118
136
]
119
137
120
138
nested_conditions_test_params = [
121
139
(
122
- 1 , f"R DELETE FROM '{ FILE_DIR_TEST_DIRECTORY } ' WHERE "
123
- "size[b] = 0 AND (filetype = '.txt' OR type = '.mp3')"
140
+ 1 ,
141
+ f"R DELETE FROM '{ FILE_DIR_TEST_DIRECTORY } ' WHERE "
142
+ "size[b] = 0 AND (filetype = '.txt' OR type = '.mp3')" ,
124
143
),
125
144
(
126
- 2 , f"R DELETE FROM '{ FILE_DIR_TEST_DIRECTORY / 'project' } ' WHERE size[b]"
127
- "= 0 AND (type = None OR (type IN ('.txt', '.py'))) AND name != 'LICENSE'"
145
+ 2 ,
146
+ f"R DELETE FROM '{ FILE_DIR_TEST_DIRECTORY / 'project' } ' WHERE size[b]"
147
+ "= 0 AND (type = None OR (type IN ('.txt', '.py'))) AND name != 'LICENSE'" ,
128
148
),
129
149
(
130
- 3 , f"R DELETE FROM '{ FILE_DIR_TEST_DIRECTORY / 'reports' } ' WHERE"
131
- " type = '.txt' AND (((name = 'Q1.txt' OR name = 'Q3.txt')))"
150
+ 3 ,
151
+ f"R DELETE FROM '{ FILE_DIR_TEST_DIRECTORY / 'reports' } ' WHERE"
152
+ " type = '.txt' AND (((name = 'Q1.txt' OR name = 'Q3.txt')))" ,
132
153
),
133
154
]
134
155
@@ -172,14 +193,26 @@ class TestDirDeleteQuery:
172
193
173
194
basic_query_syntax_test_params = [
174
195
(1 , f"DELETE[TYPE DIR] FROM '{ FILE_DIR_TEST_DIRECTORY / 'docs' } '" ),
175
- (2 , f"DELETE[TYPE DIR] FROM '{ FILE_DIR_TEST_DIRECTORY / 'reports' } ' WHERE name LIKE '^report.*$'" ),
176
- (3 , f"DELETE[TYPE DIR] FROM '{ FILE_DIR_TEST_DIRECTORY } ' WHERE name IN ('project', 'media')" ),
196
+ (
197
+ 2 ,
198
+ f"DELETE[TYPE DIR] FROM '{ FILE_DIR_TEST_DIRECTORY / 'reports' } ' WHERE name LIKE '^report.*$'" ,
199
+ ),
200
+ (
201
+ 3 ,
202
+ f"DELETE[TYPE DIR] FROM '{ FILE_DIR_TEST_DIRECTORY } ' WHERE name IN ('project', 'media')" ,
203
+ ),
177
204
]
178
205
179
206
recursive_command_test_params = [
180
207
(1 , f"R DELETE[TYPE DIR] FROM '{ FILE_DIR_TEST_DIRECTORY / 'project' } '" ),
181
- (2 , f"R DELETE[TYPE DIR] FROM '{ FILE_DIR_TEST_DIRECTORY / 'reports' } ' WHERE name='report-2023'" ),
182
- (3 , f"R DELETE[TYPE DIR] FROM '{ FILE_DIR_TEST_DIRECTORY } ' WHERE name IN ('media', 'orders')" ),
208
+ (
209
+ 2 ,
210
+ f"R DELETE[TYPE DIR] FROM '{ FILE_DIR_TEST_DIRECTORY / 'reports' } ' WHERE name='report-2023'" ,
211
+ ),
212
+ (
213
+ 3 ,
214
+ f"R DELETE[TYPE DIR] FROM '{ FILE_DIR_TEST_DIRECTORY } ' WHERE name IN ('media', 'orders')" ,
215
+ ),
183
216
]
184
217
185
218
path_types_test_params = [
@@ -190,36 +223,45 @@ class TestDirDeleteQuery:
190
223
191
224
mixed_case_query_test_params = [
192
225
(1 , f"DeLEtE[TYPe DIR] froM '{ FILE_DIR_TEST_DIRECTORY / 'docs' } '" ),
193
- (2 , f"DElEtE[tYPE DiR] From '{ FILE_DIR_TEST_DIRECTORY / 'reports' } ' Where NamE LikE '^report.*$'" ),
194
- (3 , f"Delete[Type diR] FroM '{ FILE_DIR_TEST_DIRECTORY } ' WheRE NAMe In ('project', 'media')" ),
226
+ (
227
+ 2 ,
228
+ f"DElEtE[tYPE DiR] From '{ FILE_DIR_TEST_DIRECTORY / 'reports' } ' Where NamE LikE '^report.*$'" ,
229
+ ),
230
+ (
231
+ 3 ,
232
+ f"Delete[Type diR] FroM '{ FILE_DIR_TEST_DIRECTORY } ' WheRE NAMe In ('project', 'media')" ,
233
+ ),
195
234
]
196
235
197
236
query_conditions_test_params = [
237
+ (1 , f"DELETE[TYPE DIR] FROM '{ FILE_DIR_TEST_DIRECTORY } ' WHERE name = 'media'" ),
198
238
(
199
- 1 , f"DELETE[TYPE DIR] FROM '{ FILE_DIR_TEST_DIRECTORY } ' WHERE name = 'media'"
239
+ 2 ,
240
+ f"DELETE[TYPE DIR] FROM '{ FILE_DIR_TEST_DIRECTORY } ' WHERE "
241
+ "name IN ('orders', 'media') AND parent LIKE '^.*file_dir[/]?$'" ,
200
242
),
201
243
(
202
- 2 , f"DELETE[TYPE DIR] FROM '{ FILE_DIR_TEST_DIRECTORY } ' WHERE "
203
- "name IN ('orders', 'media') AND parent LIKE '^.*file_dir[/]?$'"
244
+ 3 ,
245
+ f"DELETE[TYPE DIR] FROM '{ FILE_DIR_TEST_DIRECTORY / 'reports' } ' WHERE"
246
+ " name = 'report-2021' OR name = 'report-2022' OR name = 'report-2023'" ,
204
247
),
205
- (
206
- 3 , f"DELETE[TYPE DIR] FROM '{ FILE_DIR_TEST_DIRECTORY / 'reports' } ' WHERE"
207
- " name = 'report-2021' OR name = 'report-2022' OR name = 'report-2023'"
208
- )
209
248
]
210
249
211
250
nested_conditions_test_params = [
212
251
(
213
- 1 , f"DELETE[TYPE DIR] FROM '{ FILE_DIR_TEST_DIRECTORY } ' WHERE parent"
214
- " LIKE '^.*file_dir[/]?$' AND (name = 'orders' OR name = 'media')"
252
+ 1 ,
253
+ f"DELETE[TYPE DIR] FROM '{ FILE_DIR_TEST_DIRECTORY } ' WHERE parent"
254
+ " LIKE '^.*file_dir[/]?$' AND (name = 'orders' OR name = 'media')" ,
215
255
),
216
256
(
217
- 2 , f"R DELETE[TYPE DIR] FROM '{ FILE_DIR_TEST_DIRECTORY } ' WHERE"
218
- " ((name IN ('src'))) AND path LIKE '^.*file_dir/src[/]?$'"
257
+ 2 ,
258
+ f"R DELETE[TYPE DIR] FROM '{ FILE_DIR_TEST_DIRECTORY } ' WHERE"
259
+ " ((name IN ('src'))) AND path LIKE '^.*file_dir/src[/]?$'" ,
219
260
),
220
261
(
221
- 3 , f"DELETE[TYPE DIR] FROM '{ FILE_DIR_TEST_DIRECTORY / 'reports' } ' WHERE path LIKE "
222
- "'^.*report-20(23|24)[/]?$' AND ((name = 'report-2023') OR ((name = 'report-2024')))"
262
+ 3 ,
263
+ f"DELETE[TYPE DIR] FROM '{ FILE_DIR_TEST_DIRECTORY / 'reports' } ' WHERE path LIKE "
264
+ "'^.*report-20(23|24)[/]?$' AND ((name = 'report-2023') OR ((name = 'report-2024')))" ,
223
265
),
224
266
]
225
267
@@ -242,7 +284,7 @@ def test_path_types(self, index: int, query: str) -> None:
242
284
def test_query_conditions (self , index : int , query : str ) -> None :
243
285
"""Tests directory delete query conditions."""
244
286
examine_delete_query (query , f"/dir/conditions/test{ index } " )
245
-
287
+
246
288
@pytest .mark .parametrize (("index" , "query" ), nested_conditions_test_params )
247
289
def test_nested_query_conditions (self , index : int , query : str ) -> None :
248
290
"""Tests nested directory delete query conditions."""
0 commit comments