Skip to content

Commit

Permalink
Merge 0bd9620 into 40467ee
Browse files Browse the repository at this point in the history
  • Loading branch information
PythonCoderAS committed Dec 26, 2019
2 parents 40467ee + 0bd9620 commit 8feda88
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
41 changes: 41 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,42 @@
"""PRAW Test Suite."""
from abc import ABC, abstractmethod


class PrawTest(ABC):
"""A class representing the root of all test cases"""

def __init__(self):
self._testcases = []
for attr in dir(self):
if attr[0:4] == "test":
self._testcases.append(getattr(self, attr))

def __repr__(self, name="Test Case"):
return "PRAW {name} [{test_number} test cases]".format(
name=self.__class__.__name__, test_number=len(self._testcases)
)

def __str__(self):
return str(self._testcases)

def __call__(self):
return self.run_all_testcases()

def __iter__(self):
return self

def __next__(self):
for item in self._testcases:
yield item

def run_all_testcases(self):
for item in dir(self):
if item[0:4] == "test":
case = getattr(self, item)
case()

@abstractmethod
def setup(self):
raise NotImplementedError(
"Make sure to run setup before starting tests."
)
7 changes: 6 additions & 1 deletion tests/integration/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@
from betamax import Betamax
from praw import Reddit

from .. import PrawTest

class IntegrationTest:

class IntegrationTest(PrawTest):
"""Base class for PRAW integration tests."""

def __repr__(self, name="Integration Test"):
return super().__repr__(name)

def setup(self):
"""Setup runs before all test cases."""
self.setup_reddit()
Expand Down
7 changes: 6 additions & 1 deletion tests/unit/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
"""PRAW Unit test suite."""
from praw import Reddit

from .. import PrawTest

class UnitTest:

class UnitTest(PrawTest):
"""Base class for PRAW unit tests."""

def __repr__(self, name="Unit Test"):
return super().__repr__(name)

def setup(self):
"""Setup runs before all test cases."""
self.reddit = Reddit(
Expand Down

0 comments on commit 8feda88

Please sign in to comment.