Skip to content

Commit 3eec0c0

Browse files
committed
Cleaning up the template_module remnants and unused imports from the local tests for vamdc
1 parent a49831e commit 3eec0c0

File tree

1 file changed

+0
-62
lines changed

1 file changed

+0
-62
lines changed

astroquery/vamdc/tests/test_vamdc.py

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,16 @@
11
# Licensed under a 3-clause BSD style license - see LICENSE.rst
22
from __future__ import print_function
33

4-
# astroquery uses the pytest framework for testing
5-
# this is already available in astropy and does
6-
# not require a separate install. Import it using:
7-
from astropy.tests.helper import pytest
8-
9-
# It would be best if tests are separated in two
10-
# modules. This module performs tests on local data
11-
# by mocking HTTP requests and responses. To test the
12-
# same functions on the remote server, put the relevant
13-
# tests in the 'test_module_remote.py'
14-
15-
# Now import other commonly used modules for tests
164
import os
17-
import requests
18-
19-
from numpy import testing as npt
20-
from astropy.table import Table
21-
import astropy.coordinates as coord
22-
import astropy.units as u
235

24-
from ...utils.testing_tools import MockResponse
25-
26-
# finally import the module which is to be tested
27-
# and the various configuration items created
286
from ... import vamdc
29-
from ...vamdc import conf
30-
31-
# Local tests should have the corresponding data stored
32-
# in the ./data folder. This is the actual HTTP response
33-
# one would expect from the server when a valid query is made.
34-
# Its best to keep the data file small, so that testing is
35-
# quicker. When running tests locally the stored data is used
36-
# to mock the HTTP requests and response part of the query
37-
# thereby saving time and bypassing unreliability for
38-
# an actual remote network query.
397

40-
DATA_FILES = {'GET':
41-
# You might have a different response for each URL you're
42-
# querying:
43-
{'http://dummy_server_mirror_1':
44-
'dummy.dat'}}
458

46-
47-
# ./setup_package.py helps the test function locate the data file
48-
# define a function that can construct the full path to the file in the
49-
# ./data directory:
509
def data_path(filename):
5110
data_dir = os.path.join(os.path.dirname(__file__), 'data')
5211
return os.path.join(data_dir, filename)
5312

5413

55-
# define a monkeypatch replacement request function that returns the
56-
# dummy HTTP response for the dummy 'get' function, by
57-
# reading in data from some data file:
58-
def nonremote_request(self, request_type, url, **kwargs):
59-
# kwargs are ignored in this case, but they don't have to be
60-
# (you could use them to define which data file to read)
61-
with open(data_path(DATA_FILES[request_type][url]), 'rb') as f:
62-
response = MockResponse(content=f.read(), url=url)
63-
return response
64-
65-
66-
# use a pytest fixture to create a dummy 'requests.get' function,
67-
# that mocks(monkeypatches) the actual 'requests.get' function:
68-
@pytest.fixture
69-
def patch_request(request):
70-
mp = request.getfuncargvalue("monkeypatch")
71-
mp.setattr(vamdc.core.VamdcClass, '_request',
72-
nonremote_request)
73-
return mp
74-
75-
7614
# finally test the methods using the mock HTTP response
7715
#def test_query_molecule(patch_request):
7816
# ch3oh = vamdc.core.VamdcClass().query_molecule('CH3OH')

0 commit comments

Comments
 (0)