MagicMock, patch, sentinel, DEFAULT, # ANY and call will be imported further down create_autospec, FILTER_DIR, NonCallableMock, NonCallableMagicMock, PropertyMock, __version__ as __mock_version ) NO_MOCK = False NO_MOCK_REASON = '' mock_version = [] for __part in __mock_version.split('.'): try: mock_version.append(int(__part)) except ValueError: # Non-integer value (ex. '1a') mock_version.append(__part) mock_version = tuple(mock_version) except ImportError: NO_MOCK = True NO_MOCK_REASON = 'mock python module is unavailable' mock_version = (0, 0, 0) # Let's not fail on imports by providing fake objects and classes class MagicMock(object):
MagicMock, patch, sentinel, DEFAULT, # ANY and call will be imported further down create_autospec, FILTER_DIR, NonCallableMock, NonCallableMagicMock, PropertyMock, __version__ ) NO_MOCK = False NO_MOCK_REASON = '' mock_version = [] for __part in __version__.split('.'): try: mock_version.append(int(__part)) except ValueError: # Non-integer value (ex. '1a') mock_version.append(__part) mock_version = tuple(mock_version) except ImportError as exc: NO_MOCK = True NO_MOCK_REASON = 'mock python module is unavailable' mock_version = (0, 0, 0) # Let's not fail on imports by providing fake objects and classes class MagicMock(object):
def is_mock_to_old(): major, minor, patch = __version__.split(".") if int(major) == 0 and int(minor) < 8: return True else: return False
Mock, MagicMock, patch, sentinel, DEFAULT, # ANY and call will be imported further down create_autospec, FILTER_DIR, NonCallableMock, NonCallableMagicMock, PropertyMock, __version__ as __mock_version) NO_MOCK = False NO_MOCK_REASON = '' mock_version = [] for __part in __mock_version.split('.'): try: mock_version.append(int(__part)) except ValueError: # Non-integer value (ex. '1a') mock_version.append(__part) mock_version = tuple(mock_version) except ImportError: NO_MOCK = True NO_MOCK_REASON = 'mock python module is unavailable' mock_version = (0, 0, 0) # Let's not fail on imports by providing fake objects and classes class MagicMock(object):
def is_mock_to_old(): major, minor, patch = __version__.split('.') if int(major) == 0 and int(minor) < 8: return True else: return False
import unittest from nose.tools import eq_, ok_ from formattedrange import FormattedRange, FormattedDateRange, main from StringIO import StringIO from mock import __version__ as mock_ver assert int(mock_ver.split('.')[0]) >= 1, "mock version: %s <= 1.0 " % mock_ver from mock import patch class TestFormattedrange(unittest.TestCase): def setUp(self): self._max = 10 def test_range_normal(self): fr = FormattedRange("a[1-%s]b" % self._max) for n, i in enumerate(fr.get()): eq_(i, "a%db" % (n + 1)) def test_range_formatted(self): # Use 2 digits numbers formatting fr = FormattedRange("a[01-%s]b" % self._max) for n, i in enumerate(fr.get()): eq_(i, "a%02db" % (n + 1)) def test_multiple_range(self): fr = FormattedRange("a[1-%s]b[1-%s]c" % (2,3)) expected = ['a1b1c', 'a1b2c', 'a1b3c', 'a2b1c', 'a2b2c', 'a2b3c'] eq_(fr.get(), expected) def test_rangewcomma(self): fr = FormattedRange("a[1-2,4-5]b")