Skip to content

Commit f9eb257

Browse files
committed
work with coverage
1 parent 917f4b9 commit f9eb257

File tree

10 files changed

+42
-11
lines changed

10 files changed

+42
-11
lines changed

.circleci/config.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ commands:
5757
command: |
5858
source $HOME/miniconda/bin/activate myenv
5959
python -m pip install -e .[test]
60-
pytest -s --cov=radian
60+
pytest -s
61+
coverage combine
6162
python -m pip install codecov
6263
codecov
6364

.coveragerc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[run]
2+
parallel = True

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ dist/
44
radian.egg-info/
55
.pytest_cache/
66
.eggs/
7+
.coverage

appveyor.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ install:
3737
- python -m pip install --upgrade setuptools pip
3838
- python -m pip install -e .[test]
3939
build_script:
40-
- pytest -s --cov=radian
41-
after_build:
40+
- pytest -s
41+
- coverage combine
4242
- python -m pip install codecov
4343
- codecov
4444
# on_failure:

radian/__init__.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
__all__ = ["get_app", "main"]
44

55

6-
def main():
6+
def main(cleanup=None):
77
import optparse
88
import os
99
import sys
@@ -22,6 +22,7 @@ def main():
2222
parser.add_option("--ask-save", action="store_true", dest="ask_save", help="Ask to save R data")
2323
parser.add_option("--restore-data", action="store_true", dest="restore_data", help="Restore previously saved objects")
2424
parser.add_option("--debug", action="store_true", dest="debug", help="Debug mode")
25+
parser.add_option("--coverage", action="store_true", dest="coverage", help=optparse.SUPPRESS_HELP)
2526

2627
options, args = parser.parse_args()
2728

@@ -71,7 +72,19 @@ def main():
7172
os.execv(sys.executable, [sys.executable, "-m", "radian"] + sys.argv[1:])
7273

7374
from .radianapp import RadianApplication
74-
RadianApplication(r_home, ver=__version__).run(options)
75+
76+
if options.coverage:
77+
import coverage
78+
cov = coverage.Coverage()
79+
cov.start()
80+
81+
def cleanup(x):
82+
cov.stop()
83+
cov.save()
84+
else:
85+
cleanup = None
86+
87+
RadianApplication(r_home, ver=__version__).run(options, cleanup)
7588

7689

7790
def get_app():

radian/__main__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
if __name__ == "__main__":
2-
from radian import main
1+
from radian import main
32

3+
if __name__ == '__main__':
44
main()

radian/radianapp.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def set_env_vars(self, options):
5252
os.environ["R_INCLUDE_DIR"] = include_dir
5353
os.environ["R_SHARE_DIR"] = share_dir
5454

55-
def run(self, options):
55+
def run(self, options, cleanup=None):
5656
from .prompt import create_radian_prompt_session
5757
from .read_console import create_read_console
5858
import rchitect
@@ -87,10 +87,13 @@ def run(self, options):
8787

8888
from . import rutils
8989
rutils.execute_key_bindings_script()
90+
if cleanup:
91+
rutils.finalizer(cleanup)
9092

9193
from . import reticulate
9294
reticulate.hooks()
9395

96+
9497
# print welcome message
9598
if options.quiet is not True:
9699
self.session.app.output.write(rchitect.interface.greeting())

radian/rutils.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,10 @@ def execute_key_bindings_script(*args):
3030
("base", "source"),
3131
os.path.join(os.path.dirname(__file__), "R", "key_bindings.R"),
3232
rcall("new.env"))
33+
34+
35+
def finalizer(cleanup):
36+
rcall(("base", "reg.finalizer"),
37+
rcall(("base", "getOption"), "rchitect.py_tools"),
38+
cleanup,
39+
onexit=True)

setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ def get_version(package):
2222

2323

2424
tests_deps = [
25+
"coverage",
2526
"pytest",
26-
"pytest-mock",
27-
"pytest-cov",
2827
"pyte>=0.8.0",
2928
"pexpect",
3029
"pywinpty" if sys.platform.startswith("win") else "ptyprocess"

tests/test_startup.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
import sys
33
from helpers import assert_equal, assert_startswith, screen_process
44

5+
radian_command = [sys.executable, "-m", "radian", "--coverage"]
6+
57

68
def test_startup():
7-
radian_command = [sys.executable, "-m", "radian"]
89

910
with screen_process(radian_command) as (screen, process):
1011
assert_startswith(lambda: screen.display[0], "R ")
@@ -16,7 +17,11 @@ def test_startup():
1617
process.sendintr()
1718
assert_startswith(lambda: screen.display[7], "r$>")
1819
assert_equal(lambda: (screen.cursor.x, screen.cursor.y), (4, 7))
20+
process.write(b"q()\n")
21+
assert_equal(lambda: process.isalive(), False)
22+
1923

24+
def test_version():
2025
with screen_process(radian_command + ["--version"]) as (screen, process):
2126
assert_startswith(lambda: screen.display[0], "radian version: ")
2227
import radian

0 commit comments

Comments
 (0)