IQSS / dataverse-client-python

Python library for writing clients that use APIs from Dataverse
http://guides.dataverse.org/en/latest/api
Apache License 2.0
32 stars 27 forks source link

explain more clearly where to put local.py before running tests #12

Open pdurbin opened 9 years ago

pdurbin commented 9 years ago

To get the tests to run I created ~/.virtualenvs/dataverse-client-python/src/dataverse/dataverse/settings/local.py but I'm not sure if this is right.

murphy:dataverse-client-python pdurbin$ workon dataverse-client-python
(dataverse-client-python)murphy:dataverse-client-python pdurbin$ cd dataverse/test
(dataverse-client-python)murphy:test pdurbin$ python -m unittest test_dataverse
..Connecting to DVN.
E....
======================================================================
ERROR: setUpClass (test_dataverse.TestDatasetOperations)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test_dataverse.py", line 98, in setUpClass
    self.dvc = Connection(TEST_HOST, TEST_TOKEN)
  File "/Users/pdurbin/.virtualenvs/dataverse-client-python/src/dataverse/dataverse/connection.py", line 19, in __init__
    self.connect()
  File "/Users/pdurbin/.virtualenvs/dataverse-client-python/src/dataverse/dataverse/connection.py", line 29, in connect
    raise UnauthorizedError('The credentials provided are invalid.')
UnauthorizedError: The credentials provided are invalid.

----------------------------------------------------------------------
Ran 6 tests in 0.138s

FAILED (errors=1)
(dataverse-client-python)murphy:test pdurbin$ vim ~/.virtualenvs/dataverse-client-python/src/dataverse/dataverse/settings/local.py
(dataverse-client-python)murphy:test pdurbin$ cat ~/.virtualenvs/dataverse-client-python/src/dataverse/dataverse/settings/local.py
TEST_HOST = "apitest.dataverse.org"
TEST_TOKEN = "25fe08c4-c7d6-458a-973c-8c461ab4e0ad"
(dataverse-client-python)murphy:test pdurbin$ python -m unittest test_dataverse
..Connecting to DVN.
Getting Dataverse
Removing any existing datasets.
Dataverse emptied.
.....
----------------------------------------------------------------------
Ran 14 tests in 36.141s

OK (skipped=1)
(dataverse-client-python)murphy:test pdurbin$ 
rliebz commented 9 years ago

To run the tests, you'll want to clone the repo rather than run from the version installed to your virtual env. The readme could specify that.

pdurbin commented 9 years ago

Ah, that makes sense. I blew away my virtualenv and made a fresh one. Now I think we should have a requirements.txt file with something like this:

lxml==3.4.3
requests==2.6.0
bleach==1.4.1

After running pip install -r requirements.txt I can run the tests like this:

$ cd dataverse/test
$ vim ../settings/local.py
$ export PYTHONPATH="../.."
$ python -m unittest test_dataverse

Please let me know if this is the wrong approach.

rliebz commented 9 years ago

That's a fine approach. Because this is intended to be a package, it may be more clear to name the file dev-requirements.txt, since the package requirements are listed in setup.py.

codersquid commented 9 years ago

you could run pip install -e . and not need a requirements.txt file.

pdurbin commented 8 years ago

you could run pip install -e . and not need a requirements.txt file.

Well, that seems to install everything under "REQUIRES" at https://github.com/IQSS/dataverse-client-python/blob/d6e2199f21cddffac37d94d4e39caeaece70ee7e/setup.py#L6 which is certainly useful ("Successfully installed bleach requests lxml dataverse html5lib six") but I'm also interested in installing everything under "TESTS_REQUIRE" at https://github.com/IQSS/dataverse-client-python/blob/d6e2199f21cddffac37d94d4e39caeaece70ee7e/setup.py#L12 so I can run the tests. Any ideas?

codersquid commented 8 years ago

@pdurbin In setup.py you could add

setup(
    name='dataverse',
    # ...
    extras_require={
        "testing": TESTS_REQUIRE,
        "somethingsomething": THAT_OTHER_THING,
    }
# and so on

and then pip install -e ".[testing]"

That type of thing drives me crazy because I can never remember the proper syntax and have to look it up every time. ymmv

also, mind you I am typing this by hand and haven't tested it.

rliebz commented 8 years ago

If you've got the repo cloned locally, the TESTS_REQUIRE packages can be installed (and the test suite run) by running:

$ python setup.py test

I haven't tested this locally, so I'm not sure if setup.py is configured for that to work correctly, but that's generally the idea of the tests_require keyword argument in the setup method.