From 5febb53706dcd184bc91b87185d745b14dbdbb22 Mon Sep 17 00:00:00 2001 From: Shlomi Fish Date: Tue, 9 Oct 2018 13:08:45 +0300 Subject: [PATCH] Extract a common module/library/header. This is Refactoring / code cleanup. See: * https://refactoring.com/catalog/extractMethod.html * https://en.wikipedia.org/wiki/Code_refactoring * https://www.refactoring.com/ * https://www.joelonsoftware.com/2002/01/23/rub-a-dub-dub/ Some small optimisations may have slipped in as well. --- tests/lib/pysol_tests/common_mocks1.py | 62 +++++++++++++++++++++++ tests/lib/pysol_tests/import_file1.py | 50 +----------------- tests/lib/pysol_tests/scorpion_canMove.py | 49 +----------------- 3 files changed, 64 insertions(+), 97 deletions(-) create mode 100644 tests/lib/pysol_tests/common_mocks1.py diff --git a/tests/lib/pysol_tests/common_mocks1.py b/tests/lib/pysol_tests/common_mocks1.py new file mode 100644 index 00000000..5d94b252 --- /dev/null +++ b/tests/lib/pysol_tests/common_mocks1.py @@ -0,0 +1,62 @@ +#! /usr/bin/env python MockItem +# -*- coding: utf-8 -*- +# vim:fenc=utf-8 +# +# Copyright © 2018 Shlomi Fish +# +# Distributed under terms of the MIT license. + +from pysollib.acard import AbstractCard +import pysollib.stack + +""" + +""" + + +class MockItem: + def __init__(self): + pass + + def tkraise(self): + return + + def addtag(self, nouse): + return + + +class MockCanvas: + def __init__(self): + self.xmargin = self.ymargin = 50 + + +class MockImages: + def __init__(self): + self.CARDW = self.CARDH = self.CARD_YOFFSET = 50 + + +class MockOpt: + def __init__(self): + self.randomize_place = False + + +class MockApp: + def __init__(self): + self.images = MockImages() + self.opt = MockOpt() + + +class MockTalon: + def __init__(self, g): + self.cards = [ + AbstractCard(1000+r*100+s*10, 0, s, r, g) + for s in range(4) for r in range(13)] + for c in self.cards: + c.item = MockItem() + + +def _empty_override(*args): + return True + + +pysollib.stack.MfxCanvasGroup = _empty_override diff --git a/tests/lib/pysol_tests/import_file1.py b/tests/lib/pysol_tests/import_file1.py index 65b0343c..c1d1e959 100644 --- a/tests/lib/pysol_tests/import_file1.py +++ b/tests/lib/pysol_tests/import_file1.py @@ -1,50 +1,9 @@ # Written by Shlomi Fish, under the MIT Expat License. import unittest -from pysollib.acard import AbstractCard from pysollib.hint import FreeCellSolver_Hint, PySolHintLayoutImportError import pysollib.stack - - -class MockItem: - def __init__(self): - pass - - def tkraise(self): - return - - def addtag(self, nouse): - return - - -class MockCanvas: - def __init__(self): - self.xmargin = self.ymargin = 50 - - -class MockImages: - def __init__(self): - self.CARDW = self.CARDH = self.CARD_YOFFSET = 50 - - -class MockOpt: - def __init__(self): - self.randomize_place = False - - -class MockApp: - def __init__(self): - self.images = MockImages() - self.opt = MockOpt() - - -class MockTalon: - def __init__(self, g): - self.cards = [ - AbstractCard(1000+r*100+s*10, 0, s, r, g) - for s in range(4) for r in range(13)] - for c in self.cards: - c.item = MockItem() +from pysol_tests.common_mocks1 import MockApp, MockCanvas, MockTalon class MockGame: @@ -63,13 +22,6 @@ class MockGame: self.preview = 0 -def _empty_override(*args): - return True - - -pysollib.stack.MfxCanvasGroup = _empty_override - - class Mock_S_Game: def __init__(self): self.s = MockGame() diff --git a/tests/lib/pysol_tests/scorpion_canMove.py b/tests/lib/pysol_tests/scorpion_canMove.py index 15b5679f..650fb986 100644 --- a/tests/lib/pysol_tests/scorpion_canMove.py +++ b/tests/lib/pysol_tests/scorpion_canMove.py @@ -4,47 +4,7 @@ import unittest from pysollib.acard import AbstractCard import pysollib.stack from pysollib.games.spider import Scorpion_RowStack - - -class MockItem: - def __init__(self): - pass - - def tkraise(self): - return - - def addtag(self, nouse): - return - - -class MockCanvas: - def __init__(self): - self.xmargin = self.ymargin = 50 - - -class MockImages: - def __init__(self): - self.CARDW = self.CARDH = self.CARD_YOFFSET = 50 - - -class MockOpt: - def __init__(self): - self.randomize_place = False - - -class MockApp: - def __init__(self): - self.images = MockImages() - self.opt = MockOpt() - - -class MockTalon: - def __init__(self, g): - self.cards = [ - AbstractCard(1000+r*100+s*10, 0, s, r, g) - for s in range(4) for r in range(13)] - for c in self.cards: - c.item = MockItem() +from pysol_tests.common_mocks1 import MockApp, MockCanvas, MockItem, MockTalon class MockGame: @@ -64,13 +24,6 @@ class MockGame: self.preview = 0 -def _empty_override(*args): - return True - - -pysollib.stack.MfxCanvasGroup = _empty_override - - class Mock_S_Game: def __init__(self): self.s = MockGame()