Skip to content

Commit

Permalink
bld: remove unittest2 dependency
Browse files Browse the repository at this point in the history
* remove unused Collection class in pptx.util along with its
TestCase-based tests
  • Loading branch information
Steve Canny committed Nov 13, 2014
1 parent 9af4cf7 commit a95ec23
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 108 deletions.
42 changes: 0 additions & 42 deletions pptx/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,48 +141,6 @@ def __new__(cls, px):
return BaseLength.__new__(cls, emu)


class Collection(object):
"""
Base class for collection classes. May also be used for part collections
that don't yet have any custom methods.
Has the following characteristics.:
* Container (implements __contains__)
* Iterable (delegates __iter__ to |list|)
* Sized (implements __len__)
* Sequence (delegates __getitem__ to |list|)
"""
def __init__(self):
super(Collection, self).__init__()
self._values_ = []

@property
def _values(self):
"""Return read-only reference to collection values (list)."""
return self._values_

def __contains__(self, item): # __iter__ would do this job by itself
"""Supports 'in' operator (e.g. 'x in collection')."""
return (item in self._values_)

def __getitem__(self, key):
"""Provides indexed access, (e.g. 'collection[0]')."""
return self._values_.__getitem__(key)

def __iter__(self):
"""Supports iteration (e.g. 'for x in collection: pass')."""
return self._values_.__iter__()

def __len__(self):
"""Supports len() function (e.g. 'len(collection) == 1')."""
return len(self._values_)

def index(self, item):
"""Supports index method (e.g. '[1, 2, 3].index(2) == 1')."""
return self._values_.index(item)


def lazyproperty(f):
"""
@lazyprop decorator. Decorated method will be called only on first access
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ mock>=1.0.1
Pillow>=2.6.1
pyparsing>=2.0.1
pytest>=2.5
unittest2>=0.5.1
XlsxWriter>=0.5.7
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

INSTALL_REQUIRES = ['lxml>=3.1.0', 'Pillow>=2.6.1', 'XlsxWriter>=0.5.7']
TEST_SUITE = 'tests'
TESTS_REQUIRE = ['behave', 'mock', 'pyparsing>=2.0.1', 'pytest', 'unittest2']
TESTS_REQUIRE = ['behave', 'mock', 'pyparsing>=2.0.1', 'pytest']

CLASSIFIERS = [
'Development Status :: 4 - Beta',
Expand Down
54 changes: 4 additions & 50 deletions tests/test_util.py
Original file line number Diff line number Diff line change
@@ -1,71 +1,25 @@
# encoding: utf-8

"""Test suite for pptx.util module."""
"""
Test suite for pptx.util module.
"""

from __future__ import absolute_import

import platform
import pytest

from pptx.util import (
BaseLength, Centipoints, Cm, Collection, Emu, Inches, Mm, Pt, Px,
to_unicode
BaseLength, Centipoints, Cm, Emu, Inches, Mm, Pt, Px, to_unicode
)

from .unitutil.legacy import TestCase


def test_to_unicode_raises_on_non_string():
"""to_unicode(text) raises on *text* not a string"""
with pytest.raises(TypeError):
to_unicode(999)


class TestCollection(TestCase):
"""Test Collection"""
def setUp(self):
self.collection = Collection()

def test_indexable(self):
"""Collection is indexable (e.g. no TypeError on 'collection[0]')"""
# verify ----------------------
try:
self.collection[0]
except TypeError:
msg = "'Collection' object does not support indexing"
self.fail(msg)
except IndexError:
pass

def test_is_container(self):
"""Collection is container (e.g. 'x in collection' works)"""
# verify ----------------------
try:
1 in self.collection
except TypeError:
msg = "'Collection' object is not container"
self.fail(msg)

def test_iterable(self):
"""Collection is iterable"""
# verify ----------------------
try:
for x in self.collection:
pass
except TypeError:
msg = "'Collection' object is not iterable"
self.fail(msg)

def test_sized(self):
"""Collection is sized (e.g. 'len(collection)' works)"""
# verify ----------------------
try:
len(self.collection)
except TypeError:
msg = "object of type 'Collection' has no len()"
self.fail(msg)


class DescribeLength(object):

def it_can_construct_from_convenient_units(self, construct_fixture):
Expand Down
13 changes: 0 additions & 13 deletions tests/unitutil/legacy.py

This file was deleted.

1 change: 0 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ envlist = py26, py27

[testenv]
deps =
unittest2
mock
pyparsing>=2.0.1
pytest
Expand Down

0 comments on commit a95ec23

Please sign in to comment.