Skip to content

Commit 6d52822

Browse files
committed
chore: add benchmarks
1 parent 76a4832 commit 6d52822

File tree

8 files changed

+56
-22
lines changed

8 files changed

+56
-22
lines changed

.circleci/config.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ build: &build
1818
name: Test 35
1919
command: |
2020
cp build/lib/py_sourcemap/*.so py_sourcemap/ && \
21-
nosetests
21+
pytest
2222
- run:
2323
name: Prune the output files
2424
command: |
@@ -37,8 +37,8 @@ deploy: &deploy
3737
steps:
3838
- attach_workspace:
3939
at: "."
40-
- run:
41-
name: 'Deploy to Github Release'
40+
- run:
41+
name: "Deploy to Github Release"
4242
command: |
4343
if git log -1 --pretty=%B | grep "^[0-9]\+\.[0-9]\+\.[0-9]\+$";
4444
then
@@ -78,7 +78,7 @@ jobs:
7878
<<: *build
7979
docker:
8080
- image: broooooklyn/rust-python:3.5
81-
81+
8282
build36:
8383
<<: *build
8484
docker:
@@ -88,7 +88,7 @@ jobs:
8888
<<: *build
8989
docker:
9090
- image: broooooklyn/rust-python:3.7
91-
91+
9292
deploy35: *deploy
9393

9494
deploy36: *deploy
@@ -101,8 +101,8 @@ jobs:
101101
working_directory: /mnt/crate
102102
steps:
103103
- checkout
104-
- run:
105-
name: 'Deploy to Github Release'
104+
- run:
105+
name: "Deploy to Github Release"
106106
command: |
107107
if git log -1 --pretty=%B | grep "^[0-9]\+\.[0-9]\+\.[0-9]\+$";
108108
then

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ build
77
.eggs
88
*.egg-info
99
dist
10+
.pytest_cache
1011

1112
# editor related
1213
.vscode

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ script: |
2525
cp build/lib/py_sourcemap/*.so py_sourcemap/py_sourcemap.so && \
2626
mkdir -p natives && \
2727
cp py_sourcemap/py_sourcemap.so "natives/py_sourcemap.cpython-${PYTHON_NATIVE_ABI}m-x86_64-apple-darwin.so" && \
28-
$HOME/.local/bin/nosetests
28+
$HOME/.local/bin/pytest
2929
3030
deploy:
3131
provider: releases

appveyor.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
environment:
2-
32
matrix:
43
# For Python versions available on Appveyor, see
54
# http://www.appveyor.com/docs/installed-software#python
@@ -62,7 +61,7 @@ test_script:
6261
# Note that you must use the environment variable %PYTHON% to refer to
6362
# the interpreter you're using - Appveyor does not do anything special
6463
# to put the Python version you want to use on PATH.
65-
- "%PYTHON%\\python.exe -m nose"
64+
- "%PYTHON%\\python.exe -m pytest"
6665

6766
after_test:
6867
# This step builds your wheels.
@@ -84,5 +83,5 @@ deploy:
8483
draft: false
8584
prerelease: false
8685
on:
87-
branch: master # release from master branch only
88-
appveyor_repo_tag: true # deploy on tag push only
86+
branch: master # release from master branch only
87+
appveyor_repo_tag: true # deploy on tag push only

py_sourcemap/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
from .py_sourcemap import SourcemapParser as InternalParser
1+
from .py_sourcemap import SourcemapParser
22

33
name = 'py_sourcemap'
44

5-
__all__ = ["SourcemapParser"]
5+
__all__ = ["PySourcemapParser"]
66

77

88
class Token:
@@ -29,9 +29,9 @@ def __repr__(self):
2929
)
3030

3131

32-
class SourcemapParser:
32+
class PySourcemapParser:
3333
def __init__(self, map_path):
34-
self.parser = InternalParser(map_path)
34+
self.parser = SourcemapParser(map_path)
3535

3636
def lookup(self, line, column):
3737
(src_line, src_col, source, name) = self.parser.original_location_for(line, column)

requirement-dev.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
yapf==0.23.0
22
twine==1.11.0
33
bumpversion==0.5.3
4-
nose==1.3.7
4+
pytest==3.7.4
5+
pytest-benchmark==3.1.1

setup.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
from urllib.request import urlopen
66

77
from setuptools import setup
8-
from setuptools.command.install import install
8+
from setuptools.command.install import install as InstallCommand
9+
from setuptools.command.test import test as TestCommand
910

1011

1112
version = '0.3.8'
@@ -16,7 +17,7 @@
1617
long_description = f.read()
1718

1819

19-
class PostInstallCommand(install):
20+
class PostInstallCommand(InstallCommand):
2021
"""Post-installation for installation mode."""
2122

2223
def run(self):
@@ -51,11 +52,22 @@ def run(self):
5152
with open(dist, 'wb') as f:
5253
built_lib = urlopen(download_url).read()
5354
f.write(built_lib)
54-
install.run(self)
55+
InstallCommand.run(self)
56+
57+
58+
class PyTestCommand(TestCommand):
59+
user_options = []
60+
61+
def run(self):
62+
self.run_command('test_rust')
63+
64+
import subprocess
65+
66+
subprocess.check_call([sys.executable, '-m', 'pytest', 'tests'])
5567

5668

5769
install_requires = ['wheel']
58-
tests_require = install_requires + ['nose']
70+
tests_require = install_requires + ['pytest', 'pytest-benchmark']
5971

6072
setup(
6173
name='py-sourcemap',
@@ -79,9 +91,9 @@ def run(self):
7991
],
8092
install_requires=install_requires,
8193
tests_require=tests_require,
82-
test_suite='nose.collector',
8394
cmdclass={
8495
'install': PostInstallCommand,
96+
# 'test': PyTestCommand,
8597
},
8698
# rust extensions are not zip safe, just like C-extensions.
8799
zip_safe=False)

tests/test_benchmark.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from py_sourcemap import SourcemapParser
2+
import sourcemap
3+
4+
5+
parser = SourcemapParser('./index.js.map')
6+
min_map = open('./index.js.map', 'r').read()
7+
index = sourcemap.loads(min_map)
8+
9+
10+
def test_py_sourcemap(benchmark):
11+
token = benchmark(parser.lookup, 1, 195303)
12+
assert token.src_line == 22
13+
assert token.src_col == 41
14+
assert token.name == 'edges'
15+
16+
17+
def test_python_sourcemap(benchmark):
18+
token = benchmark(index.lookup, line=0, column=195302)
19+
assert token.src_line == 21
20+
assert token.src_col == 40
21+
assert token.name == 'edges'

0 commit comments

Comments
 (0)