Skip to content

Commit

Permalink
presents a bit of progress in reference to the cli runner
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielfalcao committed Aug 26, 2023
1 parent a24c100 commit ca94aea
Show file tree
Hide file tree
Showing 8 changed files with 366 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ docs:
$(OPEN_COMMAND) docs/build/html/index.html

test tests: clean | $(VENV)/bin/pytest # $(VENV)/bin/nosetests # @$(VENV)/bin/nosetests --rednose --immediate -vv --with-coverage --cover-package=sure
@$(VENV)/bin/pytest -vv --cov=sure
@$(VENV)/bin/pytest -vv --cov=sure tests/unit tests/functional

# run main command-line tool
run: | $(MAIN_CLI_PATH)
Expand Down
34 changes: 34 additions & 0 deletions sure/actor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# <sure - utility belt for automated testing in python>
# Copyright (C) <2010-2023> Gabriel Falcão <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os

from sure.meta import get_actor, MetaActor, gather_actor_names

__path__ = os.path.abspath(os.path.dirname(__file__))


class Actor(object, metaclass=MetaActor):
"""Base class for actors.
"""
__metaclass__ = MetaActor

def __init__(self, runner, ):
self.runner = runner

def __repr__(self):
return '<{}>'.format(self.__class__.__name__)
91 changes: 91 additions & 0 deletions sure/agent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# <sure - utility belt for automated testing in python>
# Copyright (C) <2010-2023> Gabriel Falcão <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os

from sure.meta import get_agent, MetaAgent, gather_agent_names
from sure.actors import Actor
__path__ = os.path.abspath(os.path.dirname(__file__))


class Agent(Actor):
"""Base class for agents.
The following optional methods should be implemented:
* :py:meth:`~sure.agent.Agent.on_wake`
* :py:meth:`~sure.agent.Agent.on_sleep`
* :py:meth:`~sure.agent.Agent.on_consume`
* :py:meth:`~sure.agent.Agent.on_produce`
* :py:meth:`~sure.agent.Agent.on_communication_error`
"""
__metaclass__ = MetaAgent
name = None

def __init__(self, runner, ):
self.runner = runner

def __repr__(self):
return '<{}>'.format(self.__class__.__name__)

def on_present(self):
"""Called as soon as `sure' starts running.
.. code:: python
from sure.agent import Agent
output = open('/dev/random', 'ba')
class HelloAgent(Agent):
def on_start(self):
output.write(b"sure's test runner has started")
HelloAgent(':py:class:`sure.runner.Runner`').on_start()
"""

def on_finish(self):
"""Called as soon as `sure' finishes running.
.. code:: python
from sure.agent import Agent
output = open('/dev/random', 'ba')
class HelloAgent(Agent):
def on_finish(self):
output.close()
HelloAgent(':py:class:`sure.runner.Runner`').on_finish()
"""

def on_feature(self):
"""Called as soon as `sure' finishes running.
.. code:: python
from sure.agent import Agent
output = open('/dev/random', 'ba')
class HelloAgent(Agent):
def on_finish(self):
output.close()
HelloAgent(':py:class:`sure.runner.Runner`').on_finish()
"""
48 changes: 47 additions & 1 deletion sure/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,37 @@
from pathlib import Path
from sure.importer import importer

__path__ = Path(__file__).parent.absolute()
module_root = Path(__file__).parent.absolute()

REPORTERS = {}
AGENTS = {}
ACTORS = {}


def add_agent(agent: type) -> type:
AGENTS[agent.name] = agent
return agent


def get_agent(name: str) -> type:
return AGENTS.get(name)


def gather_agent_names() -> List[str]:
return list(filter(bool, AGENTS.keys()))


def add_actor(actor: type) -> type:
ACTORS[actor.name] = actor
return actor


def get_actor(name: str) -> type:
return ACTORS.get(name)


def gather_actor_names() -> List[str]:
return list(filter(bool, ACTORS.keys()))


def add_reporter(reporter: type) -> type:
Expand All @@ -45,3 +73,21 @@ def __init__(cls, name, bases, attrs):
attrs['importer'] = cls.importer = importer

super(MetaReporter, cls).__init__(name, bases, attrs)


class MetaAgent(type):
def __init__(cls, name, bases, attrs):
if cls.__module__ != __name__:
cls = add_agent(cls)
attrs['importer'] = cls.importer = importer

super(MetaAgent, cls).__init__(name, bases, attrs)


class MetaActor(type):
def __init__(cls, name, bases, attrs):
if cls.__module__ != __name__:
cls = add_actor(cls)
attrs['importer'] = cls.importer = importer

super(MetaActor, cls).__init__(name, bases, attrs)
54 changes: 28 additions & 26 deletions sure/reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
from sure.meta import get_reporter, MetaReporter, gather_reporter_names
from sure.meta import get_agent, MetaAgent, gather_agent_names
from sure.meta import get_actor, MetaActor, gather_actor_names

__path__ = os.path.abspath(os.path.dirname(__file__))

Expand Down Expand Up @@ -65,7 +67,7 @@ def on_start(self):
"""

def on_feature(self, feature):
"""Called when a test feature is about to run
"""Called when a scenario feature is about to run
.. code:: python
Expand All @@ -76,13 +78,13 @@ def on_feature(self, feature):
sys.stderr.write('Reporter.on_feature reported {}'.format(feature.name))
class feature:
name = 'a simple test feature'
name = 'a simple scenario feature'
FeatureReporter('a <sure.runner.Runner()>').on_feature(feature)
"""

def on_feature_done(self, feature, result):
"""Called when a test feature_done is about to run
"""Called when a scenario feature_done is about to run
.. code:: python
Expand All @@ -93,89 +95,89 @@ def on_feature_done(self, feature):
sys.stderr.write('Reporter.on_feature_done reported {}'.format(feature.name))
class feature_done:
name = 'a simple test'
name = 'a simple scenario'
Feature_doneReporter('a <sure.runner.Runner()>').on_feature_done(feature_done)
"""

def on_scenario(self, test, result):
"""Called when a test test_done is about to run
def on_scenario(self, scenario, result):
"""Called when a scenario test_done is about to run
.. code:: python
from sure.reporter import Reporter
class TestReporter(Reporter):
def on_scenario_done(self, test):
sys.stderr.write('Reporter.on_scenario_done reported {}'.format(test.name))
def on_scenario_done(self, scenario):
sys.stderr.write('Reporter.on_scenario_done reported {}'.format(scenario.name))
class test_done:
name = 'a simple test'
name = 'a simple scenario'
TestReporter('a <sure.runner.Runner()>').on_scenario_done(test_done)
"""

def on_scenario_done(self, test):
"""Called when a test test_done is about to run
def on_scenario_done(self, scenario):
"""Called when a scenario test_done is about to run
.. code:: python
from sure.reporter import Reporter
class TestReporter(Reporter):
def on_scenario_done(self, test):
sys.stderr.write('Reporter.on_scenario_done reported {}'.format(test.name))
def on_scenario_done(self, scenario):
sys.stderr.write('Reporter.on_scenario_done reported {}'.format(scenario.name))
class test_done:
name = 'a simple test'
name = 'a simple scenario'
TestReporter('a <sure.runner.Runner()>').on_scenario_done(test_done)
"""

def on_failure(self, test, error):
"""Called when a test fails without crashing
def on_failure(self, scenario, error):
"""Called when a scenario fails without crashing
.. code:: python
from sure.reporter import Reporter
class FailureReporter(Reporter):
def on_failure(self, test):
sys.stderr.write('Reporter.on_failure reported {}'.format(test.name))
def on_failure(self, scenario):
sys.stderr.write('Reporter.on_failure reported {}'.format(scenario.name))
class failure:
name = 'a simple failure'
FailureReporter('a <sure.runner.Runner()>').on_failure(failure)
"""

def on_success(self, test):
"""Called when a test passes
def on_success(self, scenario):
"""Called when a scenario passes
.. code:: python
from sure.reporter import Reporter
class SuccessReporter(Reporter):
def on_success(self, test):
sys.stderr.write('Reporter.on_success reported {}'.format(test.name))
def on_success(self, scenario):
sys.stderr.write('Reporter.on_success reported {}'.format(scenario.name))
class success:
name = 'a simple success'
SuccessReporter('a <sure.runner.Runner()>').on_success(success)
"""

def on_error(self, test, error):
"""Called when a test fails with exception
def on_error(self, scenario, error):
"""Called when a scenario fails with exception
.. code:: python
from sure.reporter import Reporter
class ErrorReporter(Reporter):
def on_error(self, test):
sys.stderr.write('Reporter.on_error reported {}'.format(test.name))
def on_error(self, scenario):
sys.stderr.write('Reporter.on_error reported {}'.format(scenario.name))
class error:
name = 'a simple error'
Expand Down
Loading

0 comments on commit ca94aea

Please sign in to comment.