Skip to content

Commit

Permalink
Update tests to work with new query API
Browse files Browse the repository at this point in the history
  • Loading branch information
fred3m committed Aug 22, 2024
1 parent b202ff4 commit 8ae7daa
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 89 deletions.
11 changes: 6 additions & 5 deletions tests/test_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,13 @@ def test_load_columns_with_query(self):
"exposure.dec",
],
"query": {
"name": "EqualityQuery",
"content": {
"column": "visit1_quicklook.exp_time",
"operator": "eq",
"value": 30,
"type": "EqualityQuery",
"field": {
"schema": "visit1_quicklook",
"name": "exp_time",
},
"rightOperator": "eq",
"rightValue": 30,
},
},
}
Expand Down
166 changes: 82 additions & 84 deletions tests/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,23 @@ def test_database_query(self):

# dec > 0 (and is not None)
query1 = {
"name": "EqualityQuery",
"content": {
"column": "exposure.dec",
"operator": "gt",
"value": 0,
"type": "EqualityQuery",
"field": {
"schema": "exposure",
"name": "dec",
},
"leftOperator": "lt",
"leftValue": 0,
}
# ra > 60 (and is not None)
query2 = {
"name": "EqualityQuery",
"content": {
"column": "exposure.ra",
"operator": "gt",
"value": 60,
"type": "EqualityQuery",
"field": {
"schema": "exposure",
"name": "ra",
},
"leftOperator": "lt",
"leftValue": 60,
}

# Test 1: dec > 0 (and is not None)
Expand All @@ -117,11 +119,9 @@ def test_database_query(self):

# Test 2: dec > 0 and ra > 60 (and neither is None)
query = {
"name": "ParentQuery",
"content": {
"operator": "AND",
"children": [query1, query2],
},
"type": "ParentQuery",
"operator": "AND",
"children": [query1, query2],
}
result = self.database.query(["exposure.ra", "exposure.dec"], query=lras.query.Query.from_dict(query))
truth = data[[False, False, False, False, False, False, False, False, True, True]]
Expand All @@ -135,20 +135,16 @@ def test_database_query(self):

# Test 3: dec <= 0 or ra > 60 (and neither is None)
query = {
"name": "ParentQuery",
"content": {
"operator": "OR",
"children": [
{
"name": "ParentQuery",
"content": {
"operator": "NOT",
"children": [query1],
},
},
query2,
],
},
"type": "ParentQuery",
"operator": "OR",
"children": [
{
"type": "ParentQuery",
"operator": "NOT",
"children": [query1],
},
query2,
],
}

result = self.database.query(["exposure.ra", "exposure.dec"], query=lras.query.Query.from_dict(query))
Expand All @@ -163,11 +159,9 @@ def test_database_query(self):

# Test 4: dec > 0 XOR ra > 60
query = {
"name": "ParentQuery",
"content": {
"operator": "XOR",
"children": [query1, query2],
},
"type": "ParentQuery",
"operator": "XOR",
"children": [query1, query2],
}
result = self.database.query(["exposure.ra", "exposure.dec"], query=lras.query.Query.from_dict(query))
truth = data[[False, False, False, False, False, True, False, False, False, False]]
Expand All @@ -184,12 +178,13 @@ def test_database_string_query(self):

# Test equality
query = {
"name": "EqualityQuery",
"content": {
"column": "exposure.physical_filter",
"operator": "eq",
"value": "DECam r-band",
"type": "EqualityQuery",
"field": {
"schema": "exposure",
"name": "physical_filter",
},
"rightOperator": "eq",
"rightValue": "DECam r-band",
}
result = self.database.query(["exposure.physical_filter"], query=lras.query.Query.from_dict(query))
truth = data[[False, False, False, False, False, False, True, False, False, False]]
Expand All @@ -202,12 +197,13 @@ def test_database_string_query(self):

# Test "startswith"
query = {
"name": "EqualityQuery",
"content": {
"column": "exposure.physical_filter",
"operator": "startswith",
"value": "DECam",
"type": "EqualityQuery",
"field": {
"schema": "exposure",
"name": "physical_filter",
},
"rightOperator": "startswith",
"rightValue": "DECam",
}
result = self.database.query(["exposure.physical_filter"], query=lras.query.Query.from_dict(query))
truth = data[[False, False, False, False, False, True, True, True, True, True]]
Expand All @@ -220,12 +216,13 @@ def test_database_string_query(self):

# Test "endswith"
query = {
"name": "EqualityQuery",
"content": {
"column": "exposure.physical_filter",
"operator": "endswith",
"value": "r-band",
"type": "EqualityQuery",
"field": {
"schema": "exposure",
"name": "physical_filter",
},
"rightOperator": "endswith",
"rightValue": "r-band",
}
result = self.database.query(["exposure.physical_filter"], query=lras.query.Query.from_dict(query))
truth = data[[False, True, False, False, False, False, True, False, False, False]]
Expand All @@ -238,12 +235,13 @@ def test_database_string_query(self):

# Test "like"
query = {
"name": "EqualityQuery",
"content": {
"column": "exposure.physical_filter",
"operator": "contains",
"value": "T r",
"type": "EqualityQuery",
"field": {
"schema": "exposure",
"name": "physical_filter",
},
"rightOperator": "contains",
"rightValue": "T r",
}
result = self.database.query(["exposure.physical_filter"], query=lras.query.Query.from_dict(query))
truth = data[[False, True, False, False, False, False, False, False, False, False]]
Expand All @@ -259,12 +257,13 @@ def test_database_datatime_query(self):

# Test <
query1 = {
"name": "EqualityQuery",
"content": {
"column": "exposure.obs_start",
"operator": "lt",
"value": "2023-05-19 23:23:23",
"type": "EqualityQuery",
"field": {
"schema": "exposure",
"name": "obs_start",
},
"rightOperator": "lt",
"rightValue": "2023-05-19 23:23:23",
}
result = self.database.query(["exposure.obs_start"], query=lras.query.Query.from_dict(query1))
truth = data[[True, True, True, False, False, True, True, True, True, True]]
Expand All @@ -277,12 +276,13 @@ def test_database_datatime_query(self):

# Test >
query2 = {
"name": "EqualityQuery",
"content": {
"column": "exposure.obs_start",
"operator": "gt",
"value": "2023-05-01 23:23:23",
"type": "EqualityQuery",
"field": {
"schema": "exposure",
"name": "obs_start",
},
"leftOperator": "lt",
"leftValue": "2023-05-01 23:23:23",
}
result = self.database.query(["exposure.obs_start"], query=lras.query.Query.from_dict(query2))
truth = data[[True, True, True, True, True, False, False, False, False, False]]
Expand All @@ -295,11 +295,9 @@ def test_database_datatime_query(self):

# Test in range
query3 = {
"name": "ParentQuery",
"content": {
"operator": "AND",
"children": [query1, query2],
},
"type": "ParentQuery",
"operator": "AND",
"children": [query1, query2],
}
result = self.database.query(["exposure.obs_start"], query=lras.query.Query.from_dict(query3))
truth = data[[True, True, True, False, False, False, False, False, False, False]]
Expand All @@ -322,29 +320,29 @@ def test_multiple_table_query(self):

# dec > 0 (and is not None)
query1 = {
"name": "EqualityQuery",
"content": {
"column": "exposure.dec",
"operator": "gt",
"value": 0,
"type": "EqualityQuery",
"field": {
"schema": "exposure",
"name": "dec",
},
"leftOperator": "lt",
"leftValue": 0,
}
# exposure time == 30 (and is not None)
query2 = {
"name": "EqualityQuery",
"content": {
"column": "visit1_quicklook.exp_time",
"operator": "eq",
"value": 30,
"type": "EqualityQuery",
"field": {
"schema": "visit1_quicklook",
"name": "exp_time",
},
"rightOperator": "eq",
"rightValue": 30,
}
# Intersection of the two queries
query3 = {
"name": "ParentQuery",
"content": {
"operator": "AND",
"children": [query1, query2],
},
"type": "ParentQuery",
"operator": "AND",
"children": [query1, query2],
}

valid = (
Expand Down

0 comments on commit 8ae7daa

Please sign in to comment.