Skip to content

Commit

Permalink
gwpy.table: don't use sqlparse in tests
Browse files Browse the repository at this point in the history
it's overkill for what we use it for
  • Loading branch information
duncanmmacleod committed Apr 15, 2020
1 parent e5aefb3 commit 06d61b5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
20 changes: 10 additions & 10 deletions gwpy/table/tests/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"""

import os.path
import re
import shutil
import tempfile
from io import BytesIO
Expand All @@ -30,8 +31,6 @@

import pytest

import sqlparse

from numpy import (random, isclose, dtype, asarray, all)
from numpy.ma.core import MaskedConstant

Expand Down Expand Up @@ -69,21 +68,22 @@ def mock_hacr_connection(table, start, stop):
cursor = mock.MagicMock()

def execute(qstr):
cursor._query = sqlparse.parse(qstr)[0]
cursor._query = qstr
return len(table)

cursor.execute = execute
column_regex = re.compile(r"\Aselect (.*) from ", re.I)
select_regex = re.compile(r"where (.*) (order by .*)?\Z", re.I)

def fetchall():
q = cursor._query
name = q.get_real_name() or q._get_first_name()
if name == 'job':
if "from job" in q:
return [(1, start, stop)]
if name == 'mhacr':
columns = list(map(
str, list(cursor._query.get_sublists())[0].get_identifiers()))
selections = list(map(
str, list(cursor._query.get_sublists())[2].get_sublists()))
if "from mhacr" in q:
columns = column_regex.match(q).groups()[0].split(", ")
selections = (
select_regex.search(q).groups()[0].strip().split(" and ")
)
return map(tuple, filter_table(table, selections[3:])[columns])

cursor.fetchall = fetchall
Expand Down
1 change: 0 additions & 1 deletion requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ pytest >= 3.3.0, < 5.4.0a0 ; python_version < '3.6'
pytest-cov >= 2.4.0
pytest-xdist
requests-mock
sqlparse >= 0.2.0
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
"freezegun >= 0.2.3",
"pytest >= 3.3.0",
"pytest-cov >= 2.4.0",
"sqlparse >= 0.2.0",
]

# -- run setup ----------------------------------------------------------------
Expand Down

0 comments on commit 06d61b5

Please sign in to comment.