Skip to content

Commit

Permalink
Interactor: Remove default value for log_printer
Browse files Browse the repository at this point in the history
  • Loading branch information
sils committed Apr 15, 2015
1 parent 59e0597 commit 3f408af
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 14 deletions.
7 changes: 4 additions & 3 deletions coalib/output/ConsoleInteractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ class ConsoleInteractor(Interactor, ConsolePrinter):
STR_PROJECT_WIDE = _("Project wide:")

def __init__(self,
log_printer=ConsolePrinter(),
log_printer,
pre_padding: int=3):
"""
A ConsoleInteractor uses the Console to interact with the user.
:param output: "stdout" or "stderr".
:param pre_padding: Number of code lines to show before a result as context.
:param log_printer: The log printer to use.
:param pre_padding: Number of code lines to show before a result as
context.
"""
Interactor.__init__(self, log_printer=log_printer)
ConsolePrinter.__init__(self)
Expand Down
2 changes: 1 addition & 1 deletion coalib/output/Interactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


class Interactor(SectionCreatable, Printer):
def __init__(self, log_printer=ConsolePrinter()):
def __init__(self, log_printer):
SectionCreatable.__init__(self)
Printer.__init__(self)
self.log_printer = log_printer
Expand Down
11 changes: 8 additions & 3 deletions coalib/tests/output/ConsoleInteractorTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from coalib.settings.Section import Section, Setting
from coalib.results.RESULT_SEVERITY import RESULT_SEVERITY
from coalib.output.printers.NullPrinter import NullPrinter
from coalib.output.printers.ConsolePrinter import ConsolePrinter
from coalib.misc.i18n import _
from coalib.output.ConsoleInteractor import ConsoleInteractor
from coalib.results.result_actions.ApplyPatchAction import ApplyPatchAction
Expand All @@ -25,9 +26,10 @@ def apply(self, result, original_file_dict, file_diff_dict, param):

class ConsoleInteractorTestCase(unittest.TestCase):
def setUp(self):
self.log_printer = ConsolePrinter()
self._input = builtins.__dict__["input"]
builtins.__dict__["input"] = lambda x: x
self.uut = ConsoleInteractor()
self.uut = ConsoleInteractor(self.log_printer)

# All those tests assume that Result has no actions and PatchResult has
# one. This makes this test independent from the real number of actions
Expand All @@ -38,6 +40,7 @@ def setUp(self):
def tearDown(self):
builtins.__dict__["input"] = self._input
self.uut.close()
self.log_printer.close()

def test_require_settings(self):
self.assertRaises(TypeError, self.uut.acquire_settings, 0)
Expand Down Expand Up @@ -253,9 +256,11 @@ def test_print_results(self):

def test_from_section(self):
section = Section("test")
ConsoleInteractor.from_section(section).close()
ConsoleInteractor.from_section(section,
log_printer=self.log_printer).close()
section.append(Setting("output", "stderr"))
ConsoleInteractor.from_section(section).close()
ConsoleInteractor.from_section(section,
log_printer=self.log_printer).close()

@staticmethod
def get_str_from_queue(q):
Expand Down
5 changes: 4 additions & 1 deletion coalib/tests/output/InteractorTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@
import sys

sys.path.insert(0, ".")
from coalib.output.printers.ConsolePrinter import ConsolePrinter
from coalib.output.Interactor import Interactor
from coalib.results.Result import Result


class InteractorTestCase(unittest.TestCase):
def setUp(self):
self.uut = Interactor()
self.log_printer = ConsolePrinter()
self.uut = Interactor(self.log_printer)

def tearDown(self):
self.uut.close()
self.log_printer.close()

def test_api(self):
self.assertRaises(NotImplementedError, self.uut.acquire_settings, "anything")
Expand Down
5 changes: 4 additions & 1 deletion coalib/tests/output/NullInteractorTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@

sys.path.insert(0, ".")
from coalib.output.NullInteractor import NullInteractor
from coalib.output.printers.ConsolePrinter import ConsolePrinter
from coalib.results.Result import Result


class NullInteractorTestCase(unittest.TestCase):
def setUp(self):
self.uut = NullInteractor()
self.log_printer = ConsolePrinter()
self.uut = NullInteractor(self.log_printer)

def tearDown(self):
self.uut.close()
self.log_printer.close()

def test_api(self):
self.uut.acquire_settings([])
Expand Down
11 changes: 7 additions & 4 deletions coalib/tests/processes/SectionExecutorTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@


class SectionExecutorTestInteractor(Interactor, LogPrinter):
def __init__(self, result_queue, log_queue):
Interactor.__init__(self)
def __init__(self, log_printer, result_queue, log_queue):
Interactor.__init__(self, log_printer)
LogPrinter.__init__(self)
self.result_queue = result_queue
self.log_queue = log_queue
Expand All @@ -35,8 +35,8 @@ def begin_section(self, name):

class SectionExecutorInitTestCase(unittest.TestCase):
def test_init(self):
interactor = ConsoleInteractor()
log_printer = ConsolePrinter()
interactor = ConsoleInteractor(log_printer)
self.assertRaises(TypeError,
SectionExecutor,
5,
Expand Down Expand Up @@ -106,7 +106,9 @@ def setUp(self):
self.result_queue = queue.Queue()
self.log_queue = queue.Queue()

self.interactor = SectionExecutorTestInteractor(self.result_queue,
self.log_printer = ConsolePrinter()
self.interactor = SectionExecutorTestInteractor(self.log_printer,
self.result_queue,
self.log_queue)

self.uut = SectionExecutor(self.sections["default"],
Expand All @@ -117,6 +119,7 @@ def setUp(self):

def tearDown(self):
self.interactor.close()
self.log_printer.close()

def test_run(self):
self.assertTrue(self.uut.run())
Expand Down
2 changes: 1 addition & 1 deletion coalib/tests/settings/SectionFillerTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ class SectionFillerTestCase(unittest.TestCase):
def setUp(self):
section = Section("test")
section.append(Setting("key", "val"))
self.interactor = ConsoleInteractor()
self.log_printer = ConsolePrinter()
self.interactor = ConsoleInteractor(self.log_printer)
self.uut = SectionFiller(section,
self.interactor,
self.log_printer)
Expand Down

0 comments on commit 3f408af

Please sign in to comment.