Skip to content

Commit

Permalink
Merge pull request #90 from kytos-ng/chore/pytest
Browse files Browse the repository at this point in the history
Replace `unittest` with `pytest`
  • Loading branch information
viniarck authored Feb 9, 2024
2 parents 5cf78d3 + 7949761 commit 2e6ef12
Show file tree
Hide file tree
Showing 91 changed files with 869 additions and 1,093 deletions.
48 changes: 23 additions & 25 deletions tests/unit/test_class_inheritance/test_inheritance.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
"""Testing class inheritance attributes changes."""
import unittest

from pyof.foundation.base import GenericStruct
from pyof.foundation.basic_types import UBInt8, UBInt16, UBInt32, UBInt64


class TestInheritance(unittest.TestCase):
class TestInheritance:
"""Testing GenericStruct class inheritance."""

def setUp(self):
def setup_method(self):
"""Basic Test Setup."""
class MyClassA(GenericStruct):
"""Example class."""
Expand Down Expand Up @@ -41,30 +39,30 @@ def test_modifications(self):
m1 = self.MyClassA()
m2 = self.MyClassB()
# Checking keys (attributes names) and its ordering
self.assertEqual([attr[0] for attr in m1.get_class_attributes()],
self.a_expected_names)
self.assertEqual([attr[0] for attr in m2.get_class_attributes()],
self.b_expected_names)
assert [attr[0] for attr in m1.get_class_attributes()] == \
self.a_expected_names
assert [attr[0] for attr in m2.get_class_attributes()] == \
self.b_expected_names

# Check if there is no shared attribute between instances
self.assertIsNot(m1, m2)
self.assertIsNot(m1.a1, m2.a1)
self.assertIsNot(m1.a2, m2.a2)
self.assertIsNot(m1.a3, m2.a4)
self.assertIsNot(m1.a4, m2.a4)
self.assertIsNot(m1.a5, m2.a5)
assert m1 is not m2
assert m1.a1 is not m2.a1
assert m1.a2 is not m2.a2
assert m1.a3 is not m2.a4
assert m1.a4 is not m2.a4
assert m1.a5 is not m2.a5

# Check attributes types on MyClassA
self.assertIsInstance(self.MyClassA.a1, UBInt8)
self.assertIsInstance(self.MyClassA.a2, UBInt16)
self.assertIsInstance(self.MyClassA.a3, UBInt8)
self.assertIsInstance(self.MyClassA.a4, UBInt16)
self.assertIsInstance(self.MyClassA.a5, UBInt32)
assert isinstance(self.MyClassA.a1, UBInt8)
assert isinstance(self.MyClassA.a2, UBInt16)
assert isinstance(self.MyClassA.a3, UBInt8)
assert isinstance(self.MyClassA.a4, UBInt16)
assert isinstance(self.MyClassA.a5, UBInt32)

# Check attributes types on MyClassA
self.assertIsInstance(self.MyClassB.a1, UBInt8)
self.assertIsInstance(self.MyClassB.a2, UBInt64)
self.assertIsInstance(self.MyClassB.a4, UBInt16)
self.assertIsInstance(self.MyClassB.a5, UBInt32)
self.assertIsInstance(self.MyClassB.a0, UBInt32)
self.assertIsInstance(self.MyClassB.b6, UBInt8)
assert isinstance(self.MyClassB.a1, UBInt8)
assert isinstance(self.MyClassB.a2, UBInt64)
assert isinstance(self.MyClassB.a4, UBInt16)
assert isinstance(self.MyClassB.a5, UBInt32)
assert isinstance(self.MyClassB.a0, UBInt32)
assert isinstance(self.MyClassB.b6, UBInt8)
78 changes: 38 additions & 40 deletions tests/unit/test_foundation/test_base.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
"""Test Base module of python-openflow."""
import unittest

from pyof.foundation import base, basic_types


class TestGenericStruct(unittest.TestCase):
class TestGenericStruct:
"""Testing GenericStruct class."""

def setUp(self):
def setup_method(self):
"""Basic Test Setup."""
class AttributeA(base.GenericStruct):
"""Example class."""
Expand Down Expand Up @@ -52,46 +50,46 @@ def test_basic_attributes(self):
"""[Foundation/Base/GenericStruct] - Attributes Creation."""
message1 = self.MyMessage()
message2 = self.MyMessage()
self.assertIsNot(message1, message2)
self.assertIsNot(message1.i, message2.i)
self.assertIsNot(message1.a, message2.a)
self.assertIsNot(message1.b, message2.b)
self.assertIsNot(message1.a.a1, message2.a.a1)
self.assertIsNot(message1.a.a2, message2.a.a2)
self.assertIsNot(message1.b.c, message2.b.c)
self.assertIsNot(message1.b.c.c1, message2.b.c.c1)
self.assertIsNot(message1.b.c.c2, message2.b.c.c2)


class TestGenericType(unittest.TestCase):
assert message1 is not message2
assert message1.i is not message2.i
assert message1.a is not message2.a
assert message1.b is not message2.b
assert message1.a.a1 is not message2.a.a1
assert message1.a.a2 is not message2.a.a2
assert message1.b.c is not message2.b.c
assert message1.b.c.c1 is not message2.b.c.c1
assert message1.b.c.c2 is not message2.b.c.c2


class TestGenericType:
"""Testing GenericType class."""

def test_basic_operator(self):
"""[Foundation/Base/GenericType] - Basic Operators."""
a = basic_types.UBInt32(1)
b = basic_types.UBInt32(2)

self.assertEqual(a + 1, 2)
self.assertEqual(1 + a, 2)
self.assertEqual(b + 1, 3)
self.assertEqual(1 + b, 3)

self.assertEqual(a - 1, 0)
self.assertEqual(1 - a, 0)
self.assertEqual(b - 1, 1)
self.assertEqual(1 - b, 1)

self.assertEqual(a & 1, 1)
self.assertEqual(1 & a, 1)
self.assertEqual(b & 1, 0)
self.assertEqual(1 & b, 0)

self.assertEqual(a | 1, 1)
self.assertEqual(1 | a, 1)
self.assertEqual(b | 1, 3)
self.assertEqual(1 | b, 3)

self.assertEqual(a ^ 1, 0)
self.assertEqual(1 ^ a, 0)
self.assertEqual(b ^ 1, 3)
self.assertEqual(1 ^ b, 3)
assert a + 1 == 2
assert 1 + a == 2
assert b + 1 == 3
assert 1 + b == 3

assert a - 1 == 0
assert 1 - a == 0
assert b - 1 == 1
assert 1 - b == 1

assert a & 1 == 1
assert 1 & a == 1
assert b & 1 == 0
assert 1 & b == 0

assert a | 1 == 1
assert 1 | a == 1
assert b | 1 == 3
assert 1 | b == 3

assert a ^ 1 == 0
assert 1 ^ a == 0
assert b ^ 1 == 3
assert 1 ^ b == 3
Loading

0 comments on commit 2e6ef12

Please sign in to comment.