15
0
forked from pool/python-dukpy

Accepting request 682894 from devel:languages:python

- Update to 0.2.2:
  * State compatibility with Python 3.7
  * Provide wheels for Python 3.7
  * Fix building wheel from source distribution
  * Fix a memory leak in dukpy.evaljs
- Add patch from upstream to work well with pytest:
  * pytest.patch

OBS-URL: https://build.opensuse.org/request/show/682894
OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/python-dukpy?expand=0&rev=3
This commit is contained in:
2019-03-19 08:58:27 +00:00
committed by Git OBS Bridge
6 changed files with 256 additions and 31 deletions

3
0.2.2.tar.gz Normal file
View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:081eda6d60053dc6b141171ff6cfd5dfd037ab06d4ad5fbeaf01b850029cac3d
size 2037762

22
LICENSE
View File

@@ -1,22 +0,0 @@
The MIT License (MIT)
Copyright (c) 2015 Alessandro Molina
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:42867ca64351c945d41ccf0decd268b61e0bc626a1456efa08f1ee3ee1f1aacf
size 2008529

226
pytest.patch Normal file
View File

@@ -0,0 +1,226 @@
From 98ca8e72e55b576331c55531a6e09d61b2435540 Mon Sep 17 00:00:00 2001
From: Alessandro Molina <amol@turbogears.org>
Date: Wed, 28 Nov 2018 23:21:30 +0100
Subject: [PATCH] Move to pytest
---
.travis.yml | 4 +--
appveyor.yml | 10 +-----
dukpy/evaljs.py | 2 +-
dukpy/install.py | 2 +-
setup.py | 5 ++-
tests/{tests_evaljs.py => test_evaljs.py} | 3 +-
tests/test_installer.py | 35 ++++++++-----------
...jsinterpreter.py => test_jsinterpreter.py} | 11 +++---
tests/test_reactjs.py | 4 ++-
tests/test_transpilers.py | 11 +++---
10 files changed, 34 insertions(+), 53 deletions(-)
rename tests/{tests_evaljs.py => test_evaljs.py} (95%)
rename tests/{tests_jsinterpreter.py => test_jsinterpreter.py} (85%)
diff --git a/dukpy/evaljs.py b/dukpy/evaljs.py
index 851347e..4235b5d 100644
--- a/dukpy/evaljs.py
+++ b/dukpy/evaljs.py
@@ -8,7 +8,7 @@
try:
from collections.abc import Iterable
-except ImportError:
+except ImportError: # pragma: no cover
from collections import Iterable
try: # pragma: no cover
diff --git a/dukpy/install.py b/dukpy/install.py
index f8545e8..2c7c019 100644
--- a/dukpy/install.py
+++ b/dukpy/install.py
@@ -14,7 +14,7 @@
try:
from urllib.request import urlopen
from urllib.parse import quote_plus
-except ImportError:
+except ImportError: # pragma: no cover
from urllib2 import urlopen
from urllib import quote_plus
--- a/tests/tests_evaljs.py
+++ b/tests/tests_evaljs.py
@@ -1,13 +1,14 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
+import unittest
import logging
import os
import dukpy
import mock
-class TestEvalJS(object):
+class TestEvalJS(unittest.TestCase):
def test_object_return(self):
ans = dukpy.evaljs(["var o = {'value': 5}",
"o['value'] += 3",
diff --git a/tests/test_installer.py b/tests/test_installer.py
index 855ed0f..3a1b48c 100644
--- a/tests/test_installer.py
+++ b/tests/test_installer.py
@@ -2,18 +2,17 @@
import os
import shutil
import tempfile
+import unittest
import sys
import mock
-from nose import SkipTest
-from nose.tools import raises
import dukpy
from dukpy import install as dukpy_install
-class TestPackageInstaller(object):
- def setup(self):
+class TestPackageInstaller(unittest.TestCase):
+ def setUp(self):
self.tmpdir = tempfile.mkdtemp()
def tearDown(self):
@@ -41,14 +40,14 @@ def test_install_command_latest_ver(self):
dukpy_install.main()
assert os.path.exists(os.path.join(self.tmpdir, 'react'))
- @raises(SystemExit)
def test_install_command_missing_args(self):
- with mock.patch.object(sys, 'argv', ['dukpy-install']):
- dukpy_install.main()
+ with self.assertRaises(SystemExit):
+ with mock.patch.object(sys, 'argv', ['dukpy-install']):
+ dukpy_install.main()
def test_install_command_without_dest(self):
if os.path.exists('./js_modules'):
- raise SkipTest('local destination directory already exists...')
+ self.skipTest('local destination directory already exists...')
with mock.patch.object(sys, 'argv', ['dukpy-install', 'react', '0.14.8']):
dukpy_install.main()
@@ -65,29 +64,23 @@ def test_install_command_substrate_error(self):
assert dukpy_install.main() == 2
def test_install_unexisting_package(self):
- try:
+ with self.assertRaises(Exception) as err:
dukpy.install_jspackage('non_existing_suerly_missing_dunno', '1', self.tmpdir)
- except:
- pass
- else:
- assert False, 'Should have not found exception'
+ assert 'Not Found' in str(err.exception)
- @raises(dukpy_install.JSPackageInstallError)
def test_install_unexisting_version(self):
- dukpy.install_jspackage('react', '9999', self.tmpdir)
+ with self.assertRaises(dukpy_install.JSPackageInstallError):
+ dukpy.install_jspackage('react', '9999', self.tmpdir)
- @raises(dukpy_install.JSPackageInstallError)
def test_install_missing_download_url(self):
with mock.patch('dukpy.install._fetch_package_info',
new=lambda *args: {'versions': {'99.9.9': {}}}):
- try:
+ with self.assertRaises(dukpy_install.JSPackageInstallError) as err:
dukpy.install_jspackage('react', '99.9.9', self.tmpdir)
- except Exception as e:
- assert 'Unable to detect a supported download url' in str(e), str(e)
- raise
+ assert 'Unable to detect a supported download url' in str(err.exception)
-class TestVersionResolver(object):
+class TestVersionResolver(unittest.TestCase):
VERSIONS = {"0.14.5": {}, "0.13.0-rc2": {}, "0.13.0-rc1": {}, "0.14.0-beta3": {}, "0.2.6": {},
"0.2.5": {}, "0.2.4": {}, "0.2.3": {}, "0.2.2": {}, "0.2.1": {}, "0.2.0": {},
"0.1.2": {}, "0.3.5": {}, "0.10.0-rc1": {}, "0.14.0": {}, "0.10.0": {},
diff --git a/tests/tests_jsinterpreter.py b/tests/test_jsinterpreter.py
index 0e341b2..75cda70 100644
--- a/tests/tests_jsinterpreter.py
+++ b/tests/tests_jsinterpreter.py
@@ -1,10 +1,12 @@
+import unittest
+
from dukpy._dukpy import JSRuntimeError
import dukpy
from diffreport import report_diff
-class TestJSInterpreter(object):
+class TestJSInterpreter(unittest.TestCase):
def test_interpreter_keeps_context(self):
interpreter = dukpy.JSInterpreter()
ans = interpreter.evaljs("var o = {'value': 5}; o")
@@ -36,9 +38,6 @@ def test_module_loader(self):
def test_module_loader_unexisting(self):
interpreter = dukpy.JSInterpreter()
- try:
+ with self.assertRaises(JSRuntimeError) as err:
interpreter.evaljs("require('missing_module');")
- except JSRuntimeError as e:
- assert 'cannot find module: missing_module' in str(e)
- else:
- assert False, 'should have raised'
\ No newline at end of file
+ assert 'cannot find module: missing_module' in str(err.exception)
diff --git a/tests/test_reactjs.py b/tests/test_reactjs.py
index 3b904dc..76759fe 100644
--- a/tests/test_reactjs.py
+++ b/tests/test_reactjs.py
@@ -1,8 +1,10 @@
# -*- coding: utf-8 -*-
+import unittest
+
import dukpy
-class TestReactJS(object):
+class TestReactJS(unittest.TestCase):
def test_hello_world(self):
jsx = dukpy.jsx_compile('var react_hello = <h1>Hello, world!</h1>;')
jsi = dukpy.JSInterpreter()
diff --git a/tests/test_transpilers.py b/tests/test_transpilers.py
index f538c59..b9e383c 100644
--- a/tests/test_transpilers.py
+++ b/tests/test_transpilers.py
@@ -1,13 +1,13 @@
# -*- coding: utf-8 -*-
import os
-from unittest import TestCase
+import unittest
import dukpy
from diffreport import report_diff
from dukpy.lessc import LessCompilerError
-class TestTranspilers(TestCase):
+class TestTranspilers(unittest.TestCase):
def test_coffee(self):
ans = dukpy.coffee_compile('''
fill = (container, liquid = "coffee") ->
@@ -131,9 +131,6 @@ def test_less(self):
assert expected in ans, report_diff(expected, ans)
def test_less_errors(self):
- try:
+ with self.assertRaises(LessCompilerError) as err:
dukpy.less_compile('@import "files/missing.less";')
- except LessCompilerError as e:
- assert "files/missing.less' wasn't found." in str(e)
- else:
- assert False, 'Exception not raised'
\ No newline at end of file
+ assert "files/missing.less' wasn't found." in str(err.exception)

View File

@@ -1,3 +1,14 @@
-------------------------------------------------------------------
Fri Mar 8 14:55:28 UTC 2019 - Tomáš Chvátal <tchvatal@suse.com>
- Update to 0.2.2:
* State compatibility with Python 3.7
* Provide wheels for Python 3.7
* Fix building wheel from source distribution
* Fix a memory leak in dukpy.evaljs
- Add patch from upstream to work well with pytest:
* pytest.patch
-------------------------------------------------------------------
Thu Aug 16 09:42:12 UTC 2018 - jengelh@inai.de

View File

@@ -1,7 +1,7 @@
#
# spec file for package python-dukpy
#
# Copyright (c) 2018 SUSE LINUX GmbH, Nuernberg, Germany.
# Copyright (c) 2019 SUSE LINUX GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
@@ -12,22 +12,25 @@
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.
# Please submit bugfixes or comments via http://bugs.opensuse.org/
# Please submit bugfixes or comments via https://bugs.opensuse.org/
#
%{?!python_module:%define python_module() python-%{**} python3-%{**}}
Name: python-dukpy
Version: 0.2.0
Version: 0.2.2
Release: 0
Summary: JavaScript interpreter for Python
License: MIT
Group: Development/Languages/Python
Url: https://github.com/amol-/dukpy
Source: https://files.pythonhosted.org/packages/source/d/dukpy/dukpy-%{version}.tar.gz
Source10: https://raw.githubusercontent.com/amol-/dukpy/%{version}/LICENSE
Source: https://github.com/amol-/dukpy/archive/%{version}.tar.gz
Patch0: pytest.patch
BuildRequires: %{python_module devel}
BuildRequires: %{python_module mock}
BuildRequires: %{python_module pytest}
BuildRequires: %{python_module setuptools}
BuildRequires: %{python_module webassets}
BuildRequires: fdupes
BuildRequires: python-rpm-macros
Recommends: python-webassets
@@ -47,8 +50,12 @@ It comes with a bunch of common transpilers built-in for convenience:
%prep
%setup -q -n dukpy-%{version}
cp %{SOURCE10} .
%patch0 -p1
chmod a-x dukpy/jsmodules/react/react-dom-server.js
# remove test that relies on bunch of node binaries
rm tests/test_webassets_filter.py
# remove downloading tests
rm tests/test_installer.py
%build
export CFLAGS="%{optflags}"
@@ -58,6 +65,9 @@ export CFLAGS="%{optflags}"
%python_install
%python_expand %fdupes %{buildroot}%{$python_sitearch}
%check
%python_expand PYTHONPATH="%{buildroot}%{$python_sitearch}:%{buildroot}%{$python_sitearch}/dukpy" py.test-%{$python_bin_suffix} -v
%files %{python_files}
%doc README.rst
%license LICENSE