Skip to content

Commit

Permalink
Merge pull request #2 from ESSS/fb-ETK-PWDA-5043-create-interfaces-pa…
Browse files Browse the repository at this point in the history
…ckage

Add first version of utils collection for object oriented programming
  • Loading branch information
lincrosenbach authored Mar 11, 2019
2 parents 08296d8 + 7808a9a commit b31f0a4
Show file tree
Hide file tree
Showing 53 changed files with 7,162 additions and 67 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ __pycache__/
*$py.class
build/
dist/
docs/_build/

# Project settings
.idea/
Expand Down
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ repos:
- id: end-of-file-fixer
- id: check-yaml
- id: debug-statements
- id: flake8
- repo: local
hooks:
- id: rst
Expand Down
17 changes: 17 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>oop-ext</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.python.pydev.PyDevBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.python.pydev.pythonNature</nature>
</natures>
</projectDescription>
5 changes: 5 additions & 0 deletions .pydevproject
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?eclipse-pydev version="1.0"?><pydev_project>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python interpreter</pydev_property>
</pydev_project>
64 changes: 25 additions & 39 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,54 +1,40 @@
language: python

stages:
- test
- name: deploy
if: repo = ESSS/oop_ext AND tag IS present

install:
- pip install -U pip
- pip install -U tox

script:
- tox

jobs:
include:
- python: '3.6'
env: TOXENV=linting

- python: '3.6'
env: TOXENV=docs

- python: '2.7'
env: TOXENV=py27

- python: '3.6'
env: TOXENV=py36

- python: '3.7'
env: TOXENV=py37
sudo: required
dist: xenial

- stage: deploy
python: '3.6'
env:
install: pip install -U setuptools setuptools_scm
script: skip
deploy:
provider: pypi
distributions: sdist bdist_wheel
user: lincrosenbach
password:
# Install travis-ci CLI tool and run the command travis encrypt to generate
# the secure password
secure: REPLACE
on:
tags: true
repo: ESSS/oop_ext
python: 3.6

- python: '3.6'
env: TOXENV=linting
- python: '3.6'
env: TOXENV=docs
- python: '3.6'
env: TOXENV=py36
- python: '3.7'
env: TOXENV=py37
sudo: required
dist: xenial
- stage: deploy
python: '3.6'
env:
install: pip install -U setuptools setuptools_scm
script: skip
deploy:
provider: pypi
distributions: sdist bdist_wheel
user: lincrosenbach
password:
secure: j5/b7JtmPg4xCHShWKgNLDbXTqHI2aRzrGA/ItJmR+k6GQkeiIZy12N72F6vbx/b3HSJi9vfElVM9zzWQFAfxAk86FFpzDQ1K7kFv9haLDYG/z76j6x1Kq4QD1VYHiqY9G1XRBvTEUrwBROa76/vxC5vX0Mg8cqXpj4TLRD/qw6jCzUwmSY6garFRciAaa5ppyLdxgTSQEYZN04nT0YnxvIeNaXhQSWGI44HFAJTlxk9VRmbb5BGRP/bX2UIt//pdLsYfFMNIvR0qymQBeeFOf5H8yB4uGpKKmco1Qv415Pe7vvuZgeiL8ou1R2ZkmkdGu8taZzK8WPkzZ2Fe+KWl4joqgrU/jsYuNnwK0v7PHUGZEW7zj5lZcm1+68hjY90XsItrJy/RT6xquBZvfyOZeiOkKFtB5K8VgmnxnG0V5t9eflv0Kk3lwydFV+8fGKJA7CxMT0Qo+DMabbYlRSg6xy+AfiLEzE1hj5azs9ox2JYyoPSIcquHjxh8u5D3kmqh0E7R6KWtOIHSghHJ7MY3VbPb/QgnyvHVTOI+NvMP9uXVXAke0j1bZAscKZFsYdXnG58wqjKSmA0cXEgDyFUw8pPj46EC5ecbqZTGkRlY0C7tPXCaZx0eK79byS8tZL4D/55ffYbbVD70t8Glr0k11yOdSqK2WlXI/UXUQGCGaA=
on:
tags: true
repo: ESSS/oop_ext
python: 3.6
branches:
only:
- master
Expand Down
8 changes: 4 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
======================================================================
Oop ext
OOP Extensions
======================================================================


Expand All @@ -21,10 +21,10 @@ Oop ext
.. image:: https://img.shields.io/readthedocs/pip.svg
:target: https://oop-ext.readthedocs.io/en/latest/

What is Oop ext ?
What is OOP Extensions ?
================================================================================

OOP Extensions is a set of utilities for object orienting programming which is missing on Python core libraries.
OOP Extensions is a set of utilities for object oriented programming which is missing on Python core libraries.


Contributing
Expand All @@ -40,7 +40,7 @@ Release
-------
A reminder for the maintainers on how to make a new release.

Note that the VERSION should folow the semantic versioning as X.Y.Z
Note that the VERSION should follow the semantic versioning as X.Y.Z
Ex.: v1.0.5

1. Create a ``release-VERSION`` branch from ``upstream/master``.
Expand Down
3 changes: 0 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ environment:
- PYTHON: "C:\\Python36"
TOXENV: "docs"

- PYTHON: "C:\\Python27"
TOXENV: "py27"

- PYTHON: "C:\\Python36"
TOXENV: "py36"

Expand Down
2 changes: 1 addition & 1 deletion docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -1 +1 @@
.. include:: ../CHANGELOG
.. include:: ../CHANGELOG.RST
3 changes: 0 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
[bdist_wheel]
universal = 1

[flake8]
exclude = docs

[aliases]
test = pytest

Expand Down
5 changes: 2 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
with io.open("README.rst", encoding="UTF-8") as readme_file:
readme = readme_file.read()

with io.open("CHANGELOG", encoding="UTF-8") as changelog_file:
with io.open("CHANGELOG.RST", encoding="UTF-8") as changelog_file:
history = changelog_file.read()

requirements = []
Expand All @@ -20,7 +20,6 @@
'Development Status :: 2 - Pre-Alpha',
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
],
Expand All @@ -30,7 +29,7 @@
license="MIT license",
long_description=readme + "\n\n" + history,
include_package_data=True,
python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*",
python_requires=">=3.6",
keywords="oop_ext",
name="oop-ext",
packages=setuptools.find_packages(where="src"),
Expand Down
120 changes: 120 additions & 0 deletions src/oop_ext/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import pytest


class _ShowHandledExceptionsError:
'''
Helper class to deal with handled exceptions.
'''

def __init__(self):
self._handled_exceptions = []
self._handled_exceptions_types = []

def _OnHandledException(self):
'''
Called when a handled exceptions was found.
'''
import traceback
from io import StringIO
s = StringIO()
traceback.print_exc(file=s)
self._handled_exceptions_types.append(sys.exc_info()[0])
self._handled_exceptions.append(s.getvalue())

def __enter__(self, *args, **kwargs):
from oop_ext.foundation import handle_exception
handle_exception.on_exception_handled.Register(self._OnHandledException)
return self

def __exit__(self, *args, **kwargs):
from oop_ext.foundation import handle_exception
handle_exception.on_exception_handled.Unregister(self._OnHandledException)

def ClearHandledExceptions(self):
'''
Clears the handled exceptions
'''
del self._handled_exceptions_types[:]
del self._handled_exceptions[:]

def GetHandledExceptionTypes(self):
'''
:return list(type):
Returns a list with the exception types we found.
'''
return self._handled_exceptions_types

def GetHandledExceptions(self):
'''
:return list(str):
Returns a list with the representation of the handled exceptions.
'''
return self._handled_exceptions

def RaiseFoundExceptions(self):
'''
Raises error for the handled exceptions found.
'''

def ToString(s):
if not isinstance(s, str):
s = s.decode('utf-8', 'replace')
return s

if self._handled_exceptions:
raise AssertionError('\n'.join(ToString(i) for i in self._handled_exceptions))


@pytest.yield_fixture(scope="function", autouse=True)
def handled_exceptions():
'''
This method will be called for all the functions automatically.
For users which expect handled exceptions, it's possible to declare the fixture and
say that the errors are expected and clear them later.
I.e.:
from oop_ext.foundation.handle_exception import IgnoringHandleException
from oop_ext.foundation import handle_exception
def testSomething(handled_exceptions):
with IgnoringHandleException():
try:
raise RuntimeError('test')
except:
handle_exception.HandleException()
# Check that they're there...
assert len(handled_exceptions.GetHandledExceptions()) == 1
# Clear them
handled_exceptions.ClearHandledExceptions()
Note that test-cases can still deal with this API without using a fixture by importing handled_exceptions
and using it as an object.
I.e.:
from oop_ext.fixtures import handled_exceptions
handled_exceptions.GetHandledExceptions()
handled_exceptions.ClearHandledExceptions()
'''
try:
with _ShowHandledExceptionsError() as show_handled_exceptions_error:
handled_exceptions.ClearHandledExceptions = \
show_handled_exceptions_error.ClearHandledExceptions

handled_exceptions.GetHandledExceptions = \
show_handled_exceptions_error.GetHandledExceptions

handled_exceptions.GetHandledExceptionTypes = \
show_handled_exceptions_error.GetHandledExceptionTypes

yield show_handled_exceptions_error
finally:
handled_exceptions.ClearHandledExceptions = None
handled_exceptions.GetHandledExceptions = None
handled_exceptions.GetHandledExceptionTypes = None

show_handled_exceptions_error.RaiseFoundExceptions()
Empty file.
Empty file.
Loading

0 comments on commit b31f0a4

Please sign in to comment.