Skip to content
This repository was archived by the owner on Jun 30, 2024. It is now read-only.

Commit d5c1827

Browse files
committed
Merge branch 'tests-update' of https://github.com/bjones1/RunestoneServer into bjones1-tests-update
2 parents ac980d5 + bacb396 commit d5c1827

File tree

6 files changed

+193
-197
lines changed

6 files changed

+193
-197
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ script:
3434
- cd tests
3535
# Now actually run the tests
3636
- cp .coveragerc ../../../
37-
- python run_tests.py
37+
- pytest
3838
- cd ../../..
3939
- coveralls
4040
notifications:

scripts/dtest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# bash -c "clear && docker exec -it runestoneserver_runestone_1 bash -c 'cd applications/runestone/tests; python run_tests.py'"
33

44
echo "$@"
5-
basecomm="cd applications/runestone/tests; cp .coveragerc ../../../ ; python run_tests.py"
5+
basecomm="cd applications/runestone/tests; cp .coveragerc ../../../; pytest"
66
dcomm="$basecomm $@"
77
docker exec -it runestoneserver_runestone_1 bash -c "$dcomm"
88

tests/README.rst

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,26 @@ If you just want to run the tests:
77

88
- There are some extra modules needed, so install them
99

10-
.. code-block::
10+
.. code-block::
1111
12-
cd runestone
13-
pip install -r requirements-test.txt
12+
cd runestone
13+
pip install -r requirements-test.txt
1414
1515
16-
- Next, connect to this directory (`runestone/tests`)
16+
- Next, switch to the test directory (``runestone/tests``)
1717
- **Make sure that you don't have a runestone server running.** If you do, that server will handle the web page requests that occur during the tests instead of letting the test server respond to them, and it will be accessing the wrong database.
18+
- Run the tests. From the shell:
1819

19-
.. code-block::
20+
.. code-block::
2021
21-
python run_tests.py
22+
pytest
2223
2324
24-
Or if you have a docker container set up:
25+
Or if you have a docker container set up:
2526

26-
.. code-block::
27+
.. code-block::
2728
28-
docker exec -it runestoneserver_runestone_1 bash -c 'cd applications/runestone/tests; python run_tests.py'
29+
docker exec -it runestoneserver_runestone_1 bash -c 'cd applications/runestone/tests; pytest'
2930
3031
But we really hope you will write some tests, so lets take a look at a sample of a test that simulates a user submitting a response to a poll. We'll then check to see that their answer made it into the database, and then make sure that the api call to retrieve poll results works as expected
3132

@@ -76,9 +77,9 @@ But we really hope you will write some tests, so lets take a look at a sample of
7677
assert res[-1] == "1"
7778
7879
79-
The test above can be run as part of the entire suite of tests by running ``scripts/dtest -k test_poll`` from the Runestone main directory. This assumes that you have a Docker environment set up for your developent work. If you are not using docker then from the tests folder run ``python run_tests.py -k test_poll`` The ``-k`` option matches any part of the test names, so you don't have to give it the full test name. ``-k poll`` would run any test that has poll in its name.
80+
The test above can be run as part of the entire suite of tests by running ``scripts/dtest -k test_poll`` from the Runestone main directory. This assumes that you have a Docker environment set up for your developent work. If you are not using docker then from the tests folder run ``pytest -k test_poll`` The ``-k`` option matches any part of the test names, so you don't have to give it the full test name. ``-k poll`` would run any test that has poll in its name.
8081

81-
The ``run_tests.py`` script ensures that the database is initialized, a test book/course is created (called test_course_1) and all of the testing framework is in place. The pytest framework uses "fixtures" to help with all the gory details of setting up a test environment and creating various pieces of that environment. When you define a test_function that has one of these as a parameter name, when the test runner executes the function, the parameter will be bound to the fixture object. The fixtures include:
82+
The pytest framework uses "fixtures" to help with all the gory details of setting up a test environment and creating various pieces of that environment. When you define a test_function that has one of these as a parameter name, when the test runner executes the function, the parameter will be bound to the fixture object. The fixtures include:
8283

8384
* test_client - A client for interacting with the web2py Server
8485

@@ -250,4 +251,4 @@ From the scripts folder, run the command:
250251
locust -f locustfile.py
251252

252253

253-
Then in your browser go to `http://127.0.0.1:8089` You an set up how many users you want and how fast they will come online. The webpage will update every couple of seconds to show you statistics on load times for various kinds of pages.
254+
Then in your browser go to `http://127.0.0.1:8089` You an set up how many users you want and how fast they will come online. The webpage will update every couple of seconds to show you statistics on load times for various kinds of pages.

tests/ci_utils.py

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# Standard library
1111
# ----------------
1212
from __future__ import print_function
13-
from subprocess import check_call
13+
from subprocess import run
1414
import sys
1515
import os
1616
import os.path
@@ -24,19 +24,22 @@
2424

2525
# Copied from https://docs.python.org/3.5/library/platform.html#cross-platform.
2626
is_64bits = sys.maxsize > 2**32
27-
#
27+
28+
2829
# Support code
2930
# ============
3031
# xqt
3132
# ---
3233
# Pronounced "execute": provides a simple way to execute a system command.
3334
def xqt(
34-
# Commands to run. For example, ``'foo -param firstArg secondArg', 'bar |
35-
# grep alpha'``.
36-
*cmds,
37-
# Optional keyword arguments to pass on to `subprocess.check_call <https://docs.python.org/3/library/subprocess.html#subprocess.check_call>`_.
38-
**kwargs):
35+
# Commands to run. For example, ``'foo -param firstArg secondArg', 'bar |
36+
# grep alpha'``.
37+
*cmds,
38+
# Optional keyword arguments to pass on to `subprocess.check_call <https://docs.python.org/3/library/subprocess.html#subprocess.check_call>`_.
39+
**kwargs
40+
):
3941

42+
ret = []
4043
# Although https://docs.python.org/3/library/subprocess.html#subprocess.Popen
4144
# states, "The only time you need to specify ``shell=True`` on Windows is
4245
# when the command you wish to execute is built into the shell (e.g.
@@ -55,15 +58,21 @@ def xqt(
5558
# works. See https://docs.python.org/3/library/subprocess.html#subprocess.Popen.
5659
executable = ('/bin/bash' if is_linux or is_darwin
5760
else None)
58-
check_call(_, shell=True, executable=executable, **kwargs)
59-
#
61+
ret.append(run(_, shell=True, capture_output=True,
62+
executable=executable, **kwargs))
63+
64+
# Return a list only if there were multiple commands to execute.
65+
return ret[0] if len(ret) == 1 else ret
66+
67+
6068
# pushd
6169
# -----
6270
# A context manager for pushd.
6371
class pushd:
6472
def __init__(self,
65-
# The path to change to upon entering the context manager.
66-
path):
73+
# The path to change to upon entering the context manager.
74+
path
75+
):
6776

6877
self.path = path
6978

@@ -76,7 +85,8 @@ def __exit__(self, type_, value, traceback):
7685
flush_print('popd - returning to {}.'.format(self.cwd))
7786
os.chdir(self.cwd)
7887
return False
79-
#
88+
89+
8090
# Common tools
8191
# ============
8292
#
@@ -85,13 +95,15 @@ def __exit__(self, type_, value, traceback):
8595
def chdir(path):
8696
flush_print('cd ' + path)
8797
os.chdir(path)
88-
#
98+
99+
89100
# mkdir
90101
# -----
91102
def mkdir(path):
92103
flush_print('mkdir ' + path)
93104
os.mkdir(path)
94-
#
105+
106+
95107
# flush_print
96108
# -----------
97109
# Anything sent to ``print`` won't be printed until Python flushes its buffers,
@@ -102,14 +114,16 @@ def flush_print(*args, **kwargs):
102114
# Flush both buffers, just in case there's something in ``stdout``.
103115
sys.stdout.flush()
104116
sys.stderr.flush()
105-
#
117+
118+
106119
# isfile
107120
# ------
108121
def isfile(f):
109122
_ = os.path.isfile(f)
110123
flush_print('File {} {}.'.format(f, 'exists' if _ else 'does not exist'))
111124
return _
112-
#
125+
126+
113127
# isfile
114128
# ------
115129
def isdir(f):

0 commit comments

Comments
 (0)