Skip to content

Commit 43d9fc5

Browse files
Merge branch 'master' into fix_equality
2 parents 5a154f9 + 70d5cdb commit 43d9fc5

34 files changed

+607
-451
lines changed

.travis.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ matrix:
3232
env:
3333
- TRAVIS_RUST_VERSION=stable
3434
- REGULAR_TEST=false
35+
- CODE_COVERAGE=false
3536
script: tests/.travis-runner.sh
3637
- language: python
3738
python: 3.6
@@ -45,6 +46,7 @@ matrix:
4546
env:
4647
- TRAVIS_RUST_VERSION=beta
4748
- REGULAR_TEST=false
49+
- CODE_COVERAGE=false
4850
script: tests/.travis-runner.sh
4951
- name: rustfmt
5052
language: rust
@@ -97,6 +99,22 @@ matrix:
9799
- cargo clippy
98100
env:
99101
- REGULAR_TEST=true
102+
- name: Code Coverage
103+
language: python
104+
python: 3.6
105+
cache:
106+
pip: true
107+
# Because we're using the Python Travis environment, we can't use
108+
# the built-in cargo cacher
109+
directories:
110+
- /home/travis/.cargo
111+
- target
112+
script:
113+
- tests/.travis-runner.sh
114+
env:
115+
- TRAVIS_RUST_VERSION=nightly
116+
- REGULAR_TEST=false
117+
- CODE_COVERAGE=true
100118
allow_failures:
101119
- rust: nightly
102120
env: REGULAR_TEST=true

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
A Python-3 (CPython >= 3.5.0) Interpreter written in Rust :snake: :scream: :metal:.
44

55
[![Build Status](https://travis-ci.org/RustPython/RustPython.svg?branch=master)](https://travis-ci.org/RustPython/RustPython)
6+
[![codecov](https://codecov.io/gh/RustPython/RustPython/branch/master/graph/badge.svg)](https://codecov.io/gh/RustPython/RustPython)
67
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)
78
[![Contributors](https://img.shields.io/github/contributors/RustPython/RustPython.svg)](https://github.com/RustPython/RustPython/graphs/contributors)
89
[![Gitter](https://badges.gitter.im/RustPython/Lobby.svg)](https://gitter.im/rustpython/Lobby)

azure-pipelines.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
trigger:
2+
- master
3+
4+
jobs:
5+
6+
- job: 'Test'
7+
pool:
8+
vmImage: 'vs2017-win2016'
9+
strategy:
10+
matrix:
11+
Python37:
12+
python.version: '3.7'
13+
maxParallel: 10
14+
15+
steps:
16+
- task: UsePythonVersion@0
17+
inputs:
18+
versionSpec: '$(python.version)'
19+
architecture: 'x64'
20+
21+
- script: |
22+
"C:\Program Files\Git\mingw64\bin\curl.exe" -sSf -o rustup-init.exe https://win.rustup.rs/
23+
.\rustup-init.exe -y
24+
set PATH=%PATH%;%USERPROFILE%\.cargo\bin
25+
rustc -V
26+
cargo -V
27+
displayName: 'Installing Rust'
28+
29+
- script: |
30+
set PATH=%PATH%;%USERPROFILE%\.cargo\bin
31+
cargo build --verbose --all
32+
displayName: 'Build'
33+
34+
- script: |
35+
set PATH=%PATH%;%USERPROFILE%\.cargo\bin
36+
cargo test --verbose --all
37+
displayName: 'Run tests'
38+
39+
- script: |
40+
pip install pipenv
41+
pushd tests
42+
pipenv install
43+
popd
44+
displayName: 'Install pipenv and python packages'
45+
46+
- script: |
47+
set PATH=%PATH%;%USERPROFILE%\.cargo\bin
48+
cargo build --verbose --release
49+
displayName: 'Build release'
50+
51+
- script: |
52+
set PATH=%PATH%;%USERPROFILE%\.cargo\bin
53+
pushd tests
54+
pipenv run pytest
55+
popd
56+
displayName: 'Run snippet tests'

parser/src/python.lalrpop

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -613,17 +613,26 @@ ClassDef: ast::LocatedStatement = {
613613
},
614614
};
615615

616+
Path: ast::Expression = {
617+
<n:Identifier> => ast::Expression::Identifier { name: n },
618+
<p:Path> "." <n:name> => {
619+
ast::Expression::Attribute {
620+
value: Box::new(p),
621+
name: n,
622+
}
623+
},
624+
};
625+
616626
// Decorators:
617627
Decorator: ast::Expression = {
618-
"@" <n:DottedName> <a: ("(" ArgumentList ")")?> "\n" => {
619-
let name = ast::Expression::Identifier { name: n };
628+
"@" <p:Path> <a: ("(" ArgumentList ")")?> "\n" => {
620629
match a {
621630
Some((_, args, _)) => ast::Expression::Call {
622-
function: Box::new(name),
631+
function: Box::new(p),
623632
args: args.0,
624633
keywords: args.1,
625634
},
626-
None => name,
635+
None => p,
627636
}
628637
},
629638
};

tests/.travis-runner.sh

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,32 @@ pip install pipenv
1010
(cd tests; pipenv install)
1111

1212
# Build outside of the test runner
13-
cargo build --verbose --release
13+
if [ $CODE_COVERAGE = "true" ]
14+
then
15+
find . -name '*.gcda' -delete
16+
17+
export CARGO_INCREMENTAL=0
18+
export RUSTFLAGS="-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Zno-landing-pads"
19+
20+
cargo build --verbose
21+
else
22+
cargo build --verbose --release
23+
fi
1424

1525
# Run the tests
1626
(cd tests; pipenv run pytest)
27+
28+
if [ $CODE_COVERAGE = "true" ]
29+
then
30+
cargo test --verbose --all
31+
zip -0 ccov.zip `find . \( -name "rustpython*.gc*" \) -print`
32+
33+
# Install grcov
34+
curl -L https://github.com/mozilla/grcov/releases/download/v0.4.1/grcov-linux-x86_64.tar.bz2 | tar jxf -
35+
36+
./grcov ccov.zip -s . -t lcov --llvm --branch --ignore-not-existing --ignore-dir "/*" -p "x" > lcov.info
37+
38+
# Install codecov.io reporter
39+
curl -s https://codecov.io/bash -o codecov.sh
40+
bash codecov.sh -f lcov.info
41+
fi

tests/snippets/builtin_divmod.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,8 @@
1+
from testutils import assert_raises
2+
13
assert divmod(11, 3) == (3, 2)
24
assert divmod(8,11) == (0, 8)
35
assert divmod(0.873, 0.252) == (3.0, 0.11699999999999999)
46

5-
try:
6-
divmod(5, 0)
7-
except ZeroDivisionError:
8-
pass
9-
else:
10-
assert False, "Expected divmod by zero to throw ZeroDivisionError"
11-
12-
try:
13-
divmod(5.0, 0.0)
14-
except ZeroDivisionError:
15-
pass
16-
else:
17-
assert False, "Expected divmod by zero to throw ZeroDivisionError"
7+
assert_raises(ZeroDivisionError, lambda: divmod(5, 0), 'divmod by zero')
8+
assert_raises(ZeroDivisionError, lambda: divmod(5.0, 0.0), 'divmod by zero')

tests/snippets/builtin_format.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
1+
from testutils import assert_raises
2+
13
assert format(5, "b") == "101"
24

3-
try:
4-
format(2, 3)
5-
except TypeError:
6-
pass
7-
else:
8-
assert False, "TypeError not raised when format is called with a number"
5+
assert_raises(TypeError, lambda: format(2, 3), 'format called with number')
96

107
assert format({}) == "{}"
118

12-
try:
13-
format({}, 'b')
14-
except TypeError:
15-
pass
16-
else:
17-
assert False, "TypeError not raised when format_spec not empty for dict"
9+
assert_raises(TypeError, lambda: format({}, 'b'), 'format_spec not empty for dict')

tests/snippets/builtin_hex.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1+
from testutils import assert_raises
2+
13
assert hex(16) == '0x10'
24
assert hex(-16) == '-0x10'
35

4-
try:
5-
hex({})
6-
except TypeError:
7-
pass
8-
else:
9-
assert False, "TypeError not raised when ord() is called with a dict"
6+
assert_raises(TypeError, lambda: hex({}), 'ord() called with dict')

tests/snippets/builtin_max.py

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from testutils import assert_raises
2+
13
# simple values
24
assert max(0, 0) == 0
35
assert max(1, 0) == 1
@@ -14,32 +16,17 @@
1416
}) == "b"
1517
assert max([1, 2], default=0) == 2
1618
assert max([], default=0) == 0
17-
try:
18-
max([])
19-
except ValueError:
20-
pass
21-
else:
22-
assert False, "ValueError was not raised"
19+
assert_raises(ValueError, lambda: max([]))
2320

2421
# key parameter
2522
assert max(1, 2, -3, key=abs) == -3
2623
assert max([1, 2, -3], key=abs) == -3
2724

2825
# no argument
29-
try:
30-
max()
31-
except TypeError:
32-
pass
33-
else:
34-
assert False, "TypeError was not raised"
26+
assert_raises(TypeError, lambda: max())
3527

3628
# one non-iterable argument
37-
try:
38-
max(1)
39-
except TypeError:
40-
pass
41-
else:
42-
assert False, "TypeError was not raised"
29+
assert_raises(TypeError, lambda: max(1))
4330

4431

4532
# custom class
@@ -64,9 +51,4 @@ class MyNotComparable():
6451
pass
6552

6653

67-
try:
68-
max(MyNotComparable(), MyNotComparable())
69-
except TypeError:
70-
pass
71-
else:
72-
assert False, "TypeError was not raised"
54+
assert_raises(TypeError, lambda: max(MyNotComparable(), MyNotComparable()))

tests/snippets/builtin_min.py

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from testutils import assert_raises
2+
13
# simple values
24
assert min(0, 0) == 0
35
assert min(1, 0) == 0
@@ -14,32 +16,18 @@
1416
}) == "a"
1517
assert min([1, 2], default=0) == 1
1618
assert min([], default=0) == 0
17-
try:
18-
min([])
19-
except ValueError:
20-
pass
21-
else:
22-
assert False, "ValueError was not raised"
19+
20+
assert_raises(ValueError, lambda: min([]))
2321

2422
# key parameter
2523
assert min(1, 2, -3, key=abs) == 1
2624
assert min([1, 2, -3], key=abs) == 1
2725

2826
# no argument
29-
try:
30-
min()
31-
except TypeError:
32-
pass
33-
else:
34-
assert False, "TypeError was not raised"
27+
assert_raises(TypeError, lambda: min())
3528

3629
# one non-iterable argument
37-
try:
38-
min(1)
39-
except TypeError:
40-
pass
41-
else:
42-
assert False, "TypeError was not raised"
30+
assert_raises(TypeError, lambda: min(1))
4331

4432

4533
# custom class
@@ -64,9 +52,4 @@ class MyNotComparable():
6452
pass
6553

6654

67-
try:
68-
min(MyNotComparable(), MyNotComparable())
69-
except TypeError:
70-
pass
71-
else:
72-
assert False, "TypeError was not raised"
55+
assert_raises(TypeError, lambda: min(MyNotComparable(), MyNotComparable()))

tests/snippets/builtin_open.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1+
from testutils import assert_raises
2+
13
fd = open('README.md')
24
assert 'RustPython' in fd.read()
35

4-
try:
5-
open('DoesNotExist')
6-
assert False
7-
except FileNotFoundError:
8-
pass
6+
assert_raises(FileNotFoundError, lambda: open('DoesNotExist'))

tests/snippets/builtin_ord.py

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,9 @@
1+
from testutils import assert_raises
2+
13
assert ord("a") == 97
24
assert ord("é") == 233
35
assert ord("🤡") == 129313
4-
try:
5-
ord()
6-
except TypeError:
7-
pass
8-
else:
9-
assert False, "TypeError not raised when ord() is called with no argument"
10-
11-
try:
12-
ord("")
13-
except TypeError:
14-
pass
15-
else:
16-
assert False, "TypeError not raised when ord() is called with an empty string"
176

18-
try:
19-
ord("ab")
20-
except TypeError:
21-
pass
22-
else:
23-
assert False, "TypeError not raised when ord() is called with more than one character"
7+
assert_raises(TypeError, lambda: ord(), "ord() is called with no argument")
8+
assert_raises(TypeError, lambda: ord(""), "ord() is called with an empty string")
9+
assert_raises(TypeError, lambda: ord("ab"), "ord() is called with more than one character")

0 commit comments

Comments
 (0)