Content-Length: 715495 | pFad | http://github.com/willprice/chiplotle/commit/7ffe19aeed807430fd3d5ff4d8f7eee8b3487c47

E3 Convert old pytest raises(Error, "python code") usage to modern with-… · willprice/chiplotle@7ffe19a · GitHub
Skip to content

Commit

Permalink
Convert old pytest raises(Error, "python code") usage to modern with-…
Browse files Browse the repository at this point in the history
…clause style
  • Loading branch information
willprice committed Sep 3, 2018
1 parent 53a012f commit 7ffe19a
Showing 28 changed files with 167 additions and 102 deletions.
18 changes: 12 additions & 6 deletions src/chiplotle/geometry/core/test/test_coordinate_add.py
Original file line number Diff line number Diff line change
@@ -38,25 +38,29 @@ def test_coordinate__radd__02():
def test_coordinate__add__03():
"""A Coordinate and a float scalar cannot be added."""
a = Coordinate(1, 2)
assert raises(TypeError, "t = a + 4.2")
with raises(TypeError):
t = a + 4.2


def test_coordinate__radd__03():
"""A float scalar and a Coordinate can be added."""
a = Coordinate(1, 2)
assert raises(TypeError, "t = 4.2 + a")
with raises(TypeError):
t = 4.2 + a


def test_coordinate__add__04():
"""A Coordinate and a tuple pair cannot be added."""
a = Coordinate(1, 2)
assert raises(TypeError, "a + (3, 4)")
with raises(TypeError):
a + (3, 4)


def test_coordinate__radd__04():
"""A tuple pair and a Coordinate cannot be added."""
a = Coordinate(1, 2)
assert raises(TypeError, "(3, 4) + a")
with raises(TypeError):
(3, 4) + a


def test_coordinate__add__05():
@@ -83,11 +87,13 @@ def test_coordinate__add__06():
"""A 2D Coordinate and a triple cannot be added."""
a = Coordinate(1, 2)
b = (3, 4, 5)
assert raises(TypeError, "a + b")
with raises(TypeError):
a + b


def test_coordinate__radd__06():
"""A triple and a 2D Coordinate cannot be added."""
a = Coordinate(1, 2)
b = (3, 4, 5)
assert raises(TypeError, "b + a")
with raises(TypeError):
b + a
45 changes: 30 additions & 15 deletions src/chiplotle/geometry/core/test/test_coordinate_init.py
Original file line number Diff line number Diff line change
@@ -21,14 +21,16 @@ def test_coordinate__init__01():

def test_coordinate__init__02():
"""Coordinate cannot be initialized with a duple."""
assert raises(TypeError, "Coordinate((1, 2))")
with raises(TypeError):
Coordinate((1, 2))


def test_coordinate__init__03():
"""Coordinate cannot be initialized with a Coordinate."""
##In this case, the constructor returns the existing coordinate.'''
a = Coordinate(1, 2)
assert raises(TypeError, "t = Coordinate(a)")
with raises(TypeError):
t = Coordinate(a)


def test_coordinate__init__04():
@@ -46,12 +48,14 @@ def test_coordinate__init__05():

def test_coordinate__init__06():
"""Coordinate cannot be initialized with a triple."""
assert raises(TypeError, "t = Coordinate((1, 2, 3))")
with raises(TypeError):
t = Coordinate((1, 2, 3))


def test_coordinate__init__07():
"""Coordinate cannot be initialized with a Path."""
assert raises(TypeError, "t = Coordinate(Path([(1, 2)]))")
with raises(TypeError):
t = Coordinate(Path([(1, 2)]))


## attribute assignment ##
@@ -61,9 +65,12 @@ def test_coordinate_attribute_assignment_01():
"""Coordinates are immutable.
Attributes cannot be set (rebound)."""
t = Coordinate(1, 2)
assert raises(AttributeError, "t.xy = 2")
assert raises(AttributeError, "t.foo = 3")
assert raises(TypeError, "t[0] = 2")
with raises(AttributeError):
t.xy = 2
with raises(AttributeError):
t.foo = 3
with raises(TypeError):
t[0] = 2


## __eq__ ##
@@ -125,27 +132,31 @@ def test_coordinate__div__01():
def test_coordinate__div__02():
"""Denominator 0 raises ZeroDivisionError."""
a = Coordinate(1, 2)
assert raises(ZeroDivisionError, "t = a / 0")
with raises(ZeroDivisionError):
t = a / 0


def test_coordinate__div__03():
"""A Coordinate cannot be divided by a Coordinate."""
a = Coordinate(1, 2)
b = Coordinate(2, 4)
assert raises(TypeError, "t = a / b")
with raises(TypeError):
t = a / b


def test_coordinate__div__04():
"""A Coordinate cannot be divided by a duple."""
a = Coordinate(1, 2)
b = (2, 4)
assert raises(TypeError, "a / b")
with raises(TypeError):
a / b


def test_coordinate__div__05():
"""Division raises an Error on wrong type."""
a = Coordinate(1, 2)
assert raises(TypeError, "a / (1, 2, 3)")
with raises(TypeError):
a / (1, 2, 3)


def test_coordinate__floordiv__01():
@@ -160,19 +171,22 @@ def test_coordinate__floordiv__02():
"""Floor division does not work with two Coordinates."""
a = Coordinate(1, 2)
b = Coordinate(2, -4)
assert raises(TypeError, "t = a // b")
with raises(TypeError):
t = a // b


def test_coordinate__floordiv__03():
"""Denominator 0 raises ZeroDivisionError."""
a = Coordinate(1, 2)
assert raises(ZeroDivisionError, "t = a // 0")
with raises(ZeroDivisionError):
t = a // 0


def test_coordinate__floordiv__04():
"""Floor Division raises an OperandError on wrong type."""
a = Coordinate(1, 2)
assert raises(TypeError, "a // (1, 2, 3)")
with raises(TypeError):
a // (1, 2, 3)


## __hash__ ##
@@ -200,7 +214,8 @@ def test_coordinate__getitem__01():
t = Coordinate(1, 2)
assert t[0] == 1
assert t[1] == 2
assert raises(IndexError, "t[3]")
with raises(IndexError):
t[3]


## __len__ ##
3 changes: 2 additions & 1 deletion src/chiplotle/geometry/core/test/test_coordinate_mul.py
Original file line number Diff line number Diff line change
@@ -21,7 +21,8 @@ def test_coordinate__mul__01():
def test_coordinate__mul__02():
"""A Coordinate cannot be multiplied with a pair."""
a = Coordinate(2, 3)
assert raises(TypeError, "a * (2, 3)")
with raises(TypeError):
a * (2, 3)


def test_coordinate__mul__03():
18 changes: 12 additions & 6 deletions src/chiplotle/geometry/core/test/test_coordinate_sub.py
Original file line number Diff line number Diff line change
@@ -20,34 +20,40 @@ def test_coordinate__sub__01():
def test_coordinate__sub__02():
"""Coordinate pair cannot substract a tuple."""
a = Coordinate(1, 2)
assert raises(TypeError, "a - (0.5, 0.5)")
with raises(TypeError):
a - (0.5, 0.5)


def test_coordinate__rsub__02():
"""A tuple cannot substract a Coordinate."""
a = Coordinate(1, 2)
assert raises(TypeError, "(0.5, 0.5) - a")
with raises(TypeError):
(0.5, 0.5) - a


def test_coordinate__sub__03():
"""An int cannot be substracted from a Coordinate."""
a = Coordinate(1, 2)
assert raises(TypeError, "a - 1")
with raises(TypeError):
a - 1


def test_coordinate__rsub__03():
"""A Coordinate cannot be substracted from an int."""
a = Coordinate(1, 2)
assert raises(TypeError, "1 - a")
with raises(TypeError):
1 - a


def test_coordinate__sub__04():
"""An float cannot be substracted from a Coordinate."""
a = Coordinate(1, 2)
assert raises(TypeError, "t = a - 1.5")
with raises(TypeError):
t = a - 1.5


def test_coordinate__rsub__04():
"""A Coordinate cannot be substracted from a float."""
a = Coordinate(1, 2)
assert raises(TypeError, "t = 1.5 - a")
with raises(TypeError):
t = 1.5 - a
15 changes: 10 additions & 5 deletions src/chiplotle/geometry/core/test/test_coordinatearray_add.py
Original file line number Diff line number Diff line change
@@ -23,31 +23,36 @@ def test_coordinatearray__add__02():
"""Two CoordinateArrays of different length cannot be added."""
a = CoordinateArray([(1, 2), (3, 4)])
b = CoordinateArray([(1, 1), (2, 2), (3, 3)])
assert raises(ValueError, "t = a + b")
with raises(ValueError):
t = a + b


def test_coordinatearray__add__03():
"""A CoordinateArray and an int cannot be added."""
a = CoordinateArray([(1, 2), (3, 4)])
assert raises(TypeError, "t = a + 2")
with raises(TypeError):
t = a + 2


def test_coordinatearray__radd__04():
"""An int and a CoordinateArray cannot be added."""
a = CoordinateArray([(1, 2), (3, 4)])
assert raises(TypeError, "t = 2 + a")
with raises(TypeError):
t = 2 + a


def test_coordinatearray__add__05():
"""A CoordinateArray and a float cannot be added."""
a = CoordinateArray([(1, 2), (3, 4)])
assert raises(TypeError, "t = a + 2.3")
with raises(TypeError):
t = a + 2.3


def test_coordinatearray__add__06():
"""A float and a CoordinateArray cannot be added."""
a = CoordinateArray([(1, 2), (3, 4)])
assert raises(TypeError, "t = 2.3 + a")
with raises(TypeError):
t = 2.3 + a


def test_coordinatearray__add__07():
Original file line number Diff line number Diff line change
@@ -11,7 +11,8 @@
def test_coordinatearray_append_01():
"""CoordinateArray cannot be appended an (x, y) pair."""
t = CoordinateArray()
assert raises(TypeError, "t.append((0, 0))")
with raises(TypeError):
t.append((0, 0))


def test_coordinatearray_append_02():
Original file line number Diff line number Diff line change
@@ -11,7 +11,8 @@
def test_coordinatearray_extend_01():
"""CoordinateArray cannot be extended with a list of (x, y) pairs."""
t = CoordinateArray()
assert raises(TypeError, "t.extend([(0, 0), (1, 2)])")
with raises(TypeError):
t.extend([(0, 0), (1, 2)])


def test_coordinatearray_extend_02():
@@ -26,4 +27,5 @@ def test_coordinatearray_extend_02():
def test_coordinatearray_extend_03():
"""Mixtures are not allowed."""
t = CoordinateArray()
assert raises(TypeError, "t.extend([Coordinate(0, 0), (3, 2)])")
with raises(TypeError):
t.extend([Coordinate(0, 0), (3, 2)])
Original file line number Diff line number Diff line change
@@ -46,7 +46,8 @@ def test_coordinatearray__iadd__02():
t = CoordinateArray([(1, 2), (3, 4)])
tid = id(t)
b = 1
assert raises(TypeError, "t += b")
with raises(TypeError):
t += b


## div ##
24 changes: 16 additions & 8 deletions src/chiplotle/geometry/core/test/test_path_add.py
Original file line number Diff line number Diff line change
@@ -11,17 +11,20 @@

def test_path_add_01():
"""A Path and an int cannot be added."""
assert raises(TypeError, "Path([(1, 2), (3, 4)]) + 3")
with raises(TypeError):
Path([(1, 2), (3, 4)]) + 3


def test_path_add_02():
"""A Path and a float cannot be added."""
assert raises(TypeError, "Path([(1, 2), (3, 4)]) + 3.2")
with raises(TypeError):
Path([(1, 2), (3, 4)]) + 3.2


def test_path_radd_02():
"""A float and a Path cannot be added."""
assert raises(TypeError, "3.2 + Path([(1, 2), (3, 4)])")
with raises(TypeError):
3.2 + Path([(1, 2), (3, 4)])


def test_path_add_03():
@@ -45,26 +48,30 @@ def test_path_radd_03():
def test_path_add_04():
"""A Path and a duple cannot be added."""
a = Path([(1, 2), (3, 4)])
assert raises(TypeError, "a + (1, 2)")
with raises(TypeError):
a + (1, 2)


def test_path_radd_04():
"""A duple and a Path cannot be added."""
a = Path([(1, 2), (3, 4)])
assert raises(TypeError, "(1, 2) + a")
with raises(TypeError):
(1, 2) + a


def test_path_add_05():
"""A 2D Path and a triple cannot be added."""
a = Path([(1, 2), (3, 4)])
assert raises(TypeError, "a + (1, 2, 3)")
with raises(TypeError):
a + (1, 2, 3)


def test_path_add_06():
"""A Path and a Path cannot be added."""
a = Path([(1, 2), (3, 4)])
b = Path([(2, 3)])
assert raises(TypeError, "a + b")
with raises(TypeError):
a + b


## in place addition __iadd__ ##
@@ -73,4 +80,5 @@ def test_path_add_06():
def test_path_iadd_01():
"""A float and a Path cannot be added."""
t = Path([(1, 2), (3, 4)])
assert raises(TypeError, "t += 3.2")
with raises(TypeError):
t += 3.2
9 changes: 6 additions & 3 deletions src/chiplotle/geometry/core/test/test_path_mul.py
Original file line number Diff line number Diff line change
@@ -29,16 +29,19 @@ def test_path_rmul_01():
def test_path_mul_02():
"""A Path and a duple cannot be multiplied."""
a = Path([(1, 2), (3, 4)])
assert raises(TypeError, "a * (1, 2)")
with raises(TypeError):
a * (1, 2)


def test_path_rmul_02():
"""A duple and a Path cannot be multiplied."""
a = Path([(1, 2), (3, 4)])
assert raises(TypeError, "(1, 2) * a")
with raises(TypeError):
(1, 2) * a


def test_path_mul_03():
"""A Path cannot be multiplied with a triple."""
a = Path([(1, 2), (3, 4)])
assert raises(TypeError, "a * (1, 2, 3)")
with raises(TypeError):
a * (1, 2, 3)
Loading
Oops, something went wrong.

0 comments on commit 7ffe19a

Please sign in to comment.








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/willprice/chiplotle/commit/7ffe19aeed807430fd3d5ff4d8f7eee8b3487c47

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy