Skip to content

Commit

Permalink
Add C coverage measurement (#333)
Browse files Browse the repository at this point in the history
* travis: activate c coverage measurement
* appveyor: only build master branch and PRs
* cis: reduce appveyor build matrix, fix typo in travis
* codecov: add codecov config
* tests: improve tests for c extensions
  • Loading branch information
MatthieuDartiailh committed Dec 6, 2018
1 parent e10abb3 commit 21d6bf8
Show file tree
Hide file tree
Showing 12 changed files with 906 additions and 140 deletions.
39 changes: 10 additions & 29 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
# Create a new appveyor project, using the GitHub details.
# Ideally, configure notifications to post back to GitHub. (Untested)

branches:
only:
- master

environment:
matrix:
# Version Restrictions
Expand Down Expand Up @@ -59,46 +63,23 @@ environment:
PYTHON_ARCH: "64"
PYQT_VERSION: "5"

# Does not pass tests!
# - NAME: "Py 3.4 PyQt 4 v2"
# PYTHON: "C:\\Python34-x64"
# PYTHON_VERSION: "3.4.8"
# PYTHON_ARCH: "64"
# MINICONDA: C:\Miniconda34-x64
# PYQT_VERSION: "4"
# PYTEST_QT_API: "pyqt4v2"

- NAME: "Py 2.7"
PYTHON_VERSION: "2.7.15"
PYTHON_ARCH: "64"
PYQT_VERSION: "4"
MINICONDA: C:\Miniconda-x64
# - NAME: "Py 2.7"
# PYTHON_VERSION: "2.7.15"
# PYTHON_ARCH: "64"
# PYQT_VERSION: "4"
# MINICONDA: C:\Miniconda-x64

# 32-bit versions, PyQt, latest to oldest.
# 32-bit versions, PyQt, latest

- NAME: "32-bit, Latest "
PYTHON: "C:\\Python37"
PYTHON_VERSION: "3.7.0"
PYTHON_ARCH: "32"
PYQT_VERSION: "5"

- NAME: "32-bit, Oldest"
MINICONDA: C:\Miniconda
PYTHON_VERSION: "2.7.15"
PYTHON_ARCH: "32"
PYQT_VERSION: "4"

# PySide versions
# See "allow_failures" section below.

- NAME: "PySide"
# Wheels only available up to Python 3.4, win32.
PYTHON: "C:\\Python34"
PYTHON_VERSION: "3.4.8"
PYTHON_ARCH: "32"
PYQT_VERSION: "None"
QT_API: "pyside"

- NAME: "PySide2"
PYTHON: "C:\\Python37-x64"
PYTHON_VERSION: "3.7.3"
Expand Down
13 changes: 6 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ branches:
only:
- master

matrix:
include:
env:
global:
- CPPFLAGS=--coverage
matrix:
- env: PYTHON=2.7 QT_VERSION=4 IPY_VERSION=3 SPHINX=0
- env: PYTHON=3.4 QT_VERSION=4 IPY_VERSION=3 SPHINX=0
# - env: PYTHON=3.4 QT_VERSION=4 IPY_VERSION=3 SPHINX=0
- env: PYTHON=3.5 QT_VERSION=5 IPY_VERSION=5 QSCINTILLA=0 SPHINX=0
- env: PYTHON=3.6 QT_VERSION=5 IPY_VERSION=6 QSCINTILLA=1 SPHINX=0
- env: PYTHON=3.7 QT_VERSION=5 IPY_VERSION=6 QSCINTILLA=1 SPHINX=0
Expand Down Expand Up @@ -68,9 +70,6 @@ before_install:
python setup.py install;
fi'

# Install codecov report tools
- $PIP_INSTALL codecov

install:

# Install ecpy (check that build script is not broken
Expand All @@ -97,5 +96,5 @@ script:
after_success:
- cd $TRAVIS_BUILD_DIR
- 'if [ $SPHINX -eq 0 ]; then
codecov;
bash <(curl -s https://codecov.io/bash);
fi'
29 changes: 29 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
codecov:
notify:
require_ci_to_pass: yes

coverage:
precision: 2
round: down
range: "70...100"

status:
project: yes
patch: yes
changes: no

parsers:
gcov:
branch_detection:
conditional: yes
loop: yes
method: no
macro: no

comment:
layout: "header, diff"
behavior: default
require_changes: no

ignore:
- 'enaml/core/byteplay'
207 changes: 206 additions & 1 deletion tests/test_alias.py → tests/core/test_alias.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#------------------------------------------------------------------------------
# Copyright (c) 2013, Nucleic Development Team.
# Copyright (c) 2013-2018, Nucleic Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
Expand All @@ -9,9 +9,214 @@

import pytest

from enaml.core.alias import Alias
from utils import compile_source


def test_alias_attributes():
"""Test accessing an alias attributes.
"""
source = dedent("""\
from enaml.widgets.api import *
enamldef Main(Window):
alias fd
alias fd_txt: fd.text
Field: fd:
name = 'content'
""")
win = compile_source(source, 'Main')
for alias_name, target, chain, canset in [('fd', 'fd', (), False),
('fd_txt', 'fd', ('text',), True)
]:
alias = getattr(win, alias_name)
assert alias.target == target
assert alias.chain == chain
assert alias.key
assert alias.canset is canset

with pytest.raises(TypeError):
alias.canset = 1


def test_alias_resolve():
"""Test resolving an alias.
"""
source = dedent("""\
from enaml.widgets.api import *
enamldef Main(Window):
alias ct
Container: ct:
alias fd
Field: fd:
name = 'content'
""")
win = compile_source(source, 'Main')()
key = list(win._d_storage.keys())[0]
alias = Alias('ct', (), key)
assert alias.resolve(win) == (win.ct, None)

alias = Alias('ct', ('fd',), key)
assert alias.resolve(win) == (win.ct.fd, None)

alias = Alias('ct', ('fd', 'text'), key)
assert alias.resolve(win) == ('', None)

alias.canset = True
assert alias.resolve(win) == (win.ct.fd, 'text')

alias = Alias('unknown', (), key)
with pytest.raises(RuntimeError):
alias.resolve(win)

alias = Alias('ct', ('fd', 'unknown'), key)
with pytest.raises(AttributeError):
alias.resolve(win)


def test_simple_alias_get_error():
"""Test handling an error getting a simple alias.
"""
source = dedent("""\
from enaml.widgets.api import *
enamldef Main(Window):
alias ct
Container: ct:
alias fd
Field: fd:
name = 'content'
""")
win_cls = compile_source(source, 'Main')
key = list(win_cls()._d_storage.keys())[0]
win_cls.alias = Alias('unknown', (), key)
win = win_cls()

with pytest.raises(RuntimeError) as excinfo:
win.alias
assert 'failed to load alias' in excinfo.exconly()


def test_chained_alias_get_error():
"""Test handling an error getting a chained alias.
"""
source = dedent("""\
from enaml.widgets.api import *
enamldef Main(Window):
alias ct
Container: ct:
alias fd
Field: fd:
name = 'content'
""")
win_cls = compile_source(source, 'Main')
key = list(win_cls()._d_storage.keys())[0]
win_cls.alias = Alias('ct', ('unknown',), key)
win_cls.alias2 = Alias('unknown', ('unknown',), key)
win = win_cls()

with pytest.raises(AttributeError):
win.alias
with pytest.raises(RuntimeError):
win.alias2


def test_alias_set_canset_false():
"""Test handling an error setting a simple alias.
"""
source = dedent("""\
from enaml.widgets.api import *
enamldef Main(Window):
alias ct
Container: ct:
alias fd
Field: fd:
name = 'content'
""")
win_cls = compile_source(source, 'Main')
key = list(win_cls()._d_storage.keys())[0]
win_cls.alias = Alias('unknown', (), key)
win = win_cls()

with pytest.raises(AttributeError):
win.alias = 1


def test_simple_alias_set_error():
"""Test handling an error setting a simple alias.
"""
source = dedent("""\
from enaml.widgets.api import *
enamldef Main(Window):
alias ct
Container: ct:
alias fd
Field: fd:
name = 'content'
""")
win_cls = compile_source(source, 'Main')
key = list(win_cls()._d_storage.keys())[0]
win_cls.alias = Alias('unknown', (), key)
win_cls.alias.canset = True
win = win_cls()

with pytest.raises(RuntimeError) as excinfo:
win.alias = 1
assert 'failed to load alias' in excinfo.exconly()


def test_chained_alias_set_error():
"""Test handling an error setting a chained alias.
"""
source = dedent("""\
from enaml.widgets.api import *
enamldef Main(Window):
alias ct
Container: ct:
alias fd
Field: fd:
name = 'content'
""")
win_cls = compile_source(source, 'Main')
key = list(win_cls()._d_storage.keys())[0]
win_cls.alias = Alias('ct', ('fd', 'unknown'), key)
win_cls.alias.canset = True
win_cls.alias2 = Alias('unknown', ('unknown',), key)
win_cls.alias2.canset = True
win = win_cls()

with pytest.raises(AttributeError):
win.alias = 1
with pytest.raises(RuntimeError):
win.alias2 = 1


#------------------------------------------------------------------------------
# Alias Syntax
#------------------------------------------------------------------------------
Expand Down
37 changes: 37 additions & 0 deletions tests/core/test_c_compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#------------------------------------------------------------------------------
# Copyright (c) 2018, Nucleic Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file COPYING.txt, distributed with this software.
#------------------------------------------------------------------------------
import pytest

from enaml.c_compat import _fix_co_filename


def test_fix_co_filename():
"""Test fix_co_filename.
"""
def f():
a = [i for i in range(10)]

_fix_co_filename(f.__code__, 'test')
assert f.__code__.co_filename == 'test'


def test_fix_co_filename_bad_arguments():
"""Test handling bad arguments to fix_co_filename.
"""
with pytest.raises(TypeError) as excinfo:
_fix_co_filename(None, None)
assert 'CodeType' in excinfo.exconly()\

def f():
pass

with pytest.raises(TypeError) as excinfo:
_fix_co_filename(f.__code__, None)
assert 'str' in excinfo.exconly()

0 comments on commit 21d6bf8

Please sign in to comment.