From 4b976714e054b52b52a254529dfcc1ad42dd99da Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Tue, 28 Nov 2017 11:19:41 +0100 Subject: [PATCH] Run tests with warnings and bytes warnings All warnings except expected warnings are turned into exceptions. Fixed a resource warning in schema test case. Rename Tests/ldif to Tests/data to prevent an ImportWarning with Python 2: Traceback (most recent call last): ... ImportWarning: Not importing directory 'Tests/ldif': missing __init__.py https://github.com/python-ldap/python-ldap/pull/15 Signed-off-by: Christian Heimes --- .../subschema-ipa.demo1.freeipa.org.ldif | 0 Tests/{ldif => data}/subschema-openldap-all.ldif | 0 Tests/t_ldap_schema_subentry.py | 13 ++++++++----- tox.ini | 14 +++++++++++++- 4 files changed, 21 insertions(+), 6 deletions(-) rename Tests/{ldif => data}/subschema-ipa.demo1.freeipa.org.ldif (100%) rename Tests/{ldif => data}/subschema-openldap-all.ldif (100%) diff --git a/Tests/ldif/subschema-ipa.demo1.freeipa.org.ldif b/Tests/data/subschema-ipa.demo1.freeipa.org.ldif similarity index 100% rename from Tests/ldif/subschema-ipa.demo1.freeipa.org.ldif rename to Tests/data/subschema-ipa.demo1.freeipa.org.ldif diff --git a/Tests/ldif/subschema-openldap-all.ldif b/Tests/data/subschema-openldap-all.ldif similarity index 100% rename from Tests/ldif/subschema-openldap-all.ldif rename to Tests/data/subschema-openldap-all.ldif diff --git a/Tests/t_ldap_schema_subentry.py b/Tests/t_ldap_schema_subentry.py index 83ed006..ee79072 100644 --- a/Tests/t_ldap_schema_subentry.py +++ b/Tests/t_ldap_schema_subentry.py @@ -5,6 +5,7 @@ See https://www.python-ldap.org/ for details. """ +import os import unittest import time @@ -12,9 +13,11 @@ import ldap.schema from ldap.schema.models import ObjectClass +HERE = os.path.abspath(os.path.dirname(__file__)) + TEST_SUBSCHEMA_FILES = ( - 'Tests/ldif/subschema-ipa.demo1.freeipa.org.ldif', - 'Tests/ldif/subschema-openldap-all.ldif', + os.path.join(HERE, 'data', 'subschema-ipa.demo1.freeipa.org.ldif'), + os.path.join(HERE, 'data', 'subschema-openldap-all.ldif'), ) class TestSubschemaLDIF(unittest.TestCase): @@ -25,9 +28,9 @@ class TestSubschemaLDIF(unittest.TestCase): def test_subschema_file(self): for test_file in TEST_SUBSCHEMA_FILES: # Read and parse LDIF file - ldif_file = open(test_file, 'rb') - ldif_parser = ldif.LDIFRecordList(ldif_file,max_entries=1) - ldif_parser.parse() + with open(test_file, 'rb') as ldif_file: + ldif_parser = ldif.LDIFRecordList(ldif_file,max_entries=1) + ldif_parser.parse() _, subschema_subentry = ldif_parser.all_records[0] sub_schema = ldap.schema.SubSchema(subschema_subentry) diff --git a/tox.ini b/tox.ini index b2d435c..22ca4a8 100644 --- a/tox.ini +++ b/tox.ini @@ -9,8 +9,20 @@ envlist = py27,py33,py34,py35,py36,coverage-report [testenv] deps = coverage -commands = {envpython} -m coverage run --parallel setup.py test passenv = WITH_GCOV +# - Enable BytesWarning +# - Turn all warnings into exceptions. +# - 'ignore:the imp module is deprecated' is required to ignore import of +# 'imp' in distutils. Python 3.3 and 3.4 use PendingDeprecationWarning. +commands = {envpython} -bb -Werror \ + "-Wignore:the imp module is deprecated:DeprecationWarning" \ + "-Wignore:the imp module is deprecated:PendingDeprecationWarning" \ + -m coverage run --parallel setup.py test + +[testenv:py27] +# No warnings with Python 2.7 +commands = {envpython} \ + -m coverage run --parallel setup.py test [testenv:coverage-report] deps = coverage