def testNotTooManyFeaturesByDefault(self): """ A new instance of L{_FeatureAdder} must be marked on creation as not having too many features to plot. """ featureAdder = _FeatureAdder() self.assertFalse(featureAdder.tooManyFeaturesToPlot)
def testTooManyFeatures(self): """ If the sequence fetcher used by a L{_FeatureAdder} returns too many features, the C{text} and C{axis} methods on the figure must be called correctly and the C{add} call must return the sequences. """ def fetcher(title, db="database"): feature = SeqFeature(type="site", qualifiers={"a": ["b"]}) return SeqRecord(None, features=[feature] * 100) featureAdder = _FeatureAdder() featureAdder.WANTED_TYPES = ("site",) fig = plt.subplot(111) fig.text = MagicMock() fig.axis = MagicMock() result = featureAdder.add(fig, "title", 0, 300, identity, sequenceFetcher=fetcher) fig.text.assert_called_with( 0.5, 0.5, "Too many features to plot", horizontalalignment="center", verticalalignment="center", transform=ANY, fontsize=20, ) fig.axis.assert_called_with([0, 300, -1, 1]) self.assertTrue(isinstance(result, _FeatureList)) self.assertEqual(100, len(result))
def testNoFeatures(self): """ If the sequence fetcher used by a L{_FeatureAdder} returns no features the C{text} and C{axis} methods on the fig must both be called correctly and the C{add} method must return C{[]}. """ def fetcher(title, db='database'): return SeqRecord(None) featureAdder = _FeatureAdder() featureAdder.WANTED_TYPES = ('site', ) fig = plt.subplot(111, label=_randomLabel()) fig.text = MagicMock() fig.axis = MagicMock() result = featureAdder.add(fig, 'title', 0, 300, sequenceFetcher=fetcher) fig.text.assert_called_with(0.5, 0.5, 'No features found', horizontalalignment='center', verticalalignment='center', transform=ANY, fontsize=20) fig.axis.assert_called_with([0, 300, -1, 1]) self.assertEqual([], result)
def testOneFeatureRaisesNotImplementedError(self): """ If the sequence fetcher used by a L{_FeatureAdder} returns a feature, the C{add} method must raise C{NotImplementedError} because the C{_displayFeatures} method is not implemented. """ def fetcher(title, db='database'): location = FeatureLocation(100, 200) subfeature = SeqFeature(type='region', qualifiers={'a': ['b']}, location=location) feature = SeqFeature(type='site', qualifiers={'a': ['b']}, sub_features=[subfeature], location=location) return SeqRecord(None, features=[feature]) featureAdder = _FeatureAdder() featureAdder.WANTED_TYPES = ('site', ) fig = plt.subplot(111) self.assertRaises(NotImplementedError, featureAdder.add, fig, 'title', 0, 300, sequenceFetcher=fetcher)
def testTooManyFeatures(self): """ If the sequence fetcher used by a L{_FeatureAdder} returns too many features, the C{text} and C{axis} methods on the figure must be called correctly and the C{add} call must return the sequences. """ def fetcher(title, db='database'): location = FeatureLocation(100, 200) feature = SeqFeature(type='site', qualifiers={'a': ['b']}, location=location) return SeqRecord(None, features=[feature] * 100) featureAdder = _FeatureAdder() featureAdder.WANTED_TYPES = ('site',) fig = plt.subplot(111) fig.text = MagicMock() fig.axis = MagicMock() result = featureAdder.add(fig, 'title', 0, 300, sequenceFetcher=fetcher) fig.text.assert_called_with(0.5, 0.5, 'Too many features to plot', horizontalalignment='center', verticalalignment='center', transform=ANY, fontsize=20) fig.axis.assert_called_with([0, 300, -1, 1]) self.assertTrue(isinstance(result, FeatureList)) self.assertEqual(100, len(result))
def testTooManyFeatures(self): """ If the sequence fetcher used by a L{_FeatureAdder} returns too many features, the C{text} and C{axis} methods on the figure must be called correctly and the C{add} call must return the sequences. """ def fetcher(title, db='database'): location = FeatureLocation(100, 200) feature = SeqFeature(type='site', qualifiers={'a': ['b']}, location=location) return SeqRecord(None, features=[feature] * 100) featureAdder = _FeatureAdder() featureAdder.WANTED_TYPES = ('site', ) fig = plt.subplot(111, label=_randomLabel()) fig.text = MagicMock() fig.axis = MagicMock() result = featureAdder.add(fig, 'title', 0, 300, sequenceFetcher=fetcher) fig.text.assert_called_with(0.5, 0.5, 'Too many features to plot', horizontalalignment='center', verticalalignment='center', transform=ANY, fontsize=20) fig.axis.assert_called_with([0, 300, -1, 1]) self.assertTrue(isinstance(result, FeatureList)) self.assertEqual(100, len(result))
def testYTicks(self): """ A L{_FeatureAdder} must set the title of its figure. """ fetcher = lambda title, db='database': None featureAdder = _FeatureAdder() fig = plt.subplot(111) fig.set_yticks = MagicMock() featureAdder.add(fig, 'title', 0, 100, sequenceFetcher=fetcher) fig.set_yticks.assert_called_with([])
def testTitle(self): """ A L{_FeatureAdder} must set the title of its figure. """ fetcher = lambda title, db="database": None featureAdder = _FeatureAdder() fig = plt.subplot(111) fig.set_title = MagicMock() featureAdder.add(fig, "title", 0, 100, identity, sequenceFetcher=fetcher) fig.set_title.assert_called_with("Target sequence features", fontsize=16)
def testYTicks(self): """ A L{_FeatureAdder} must set the title of its figure. """ fetcher = lambda title, db="database": None featureAdder = _FeatureAdder() fig = plt.subplot(111) fig.set_yticks = MagicMock() featureAdder.add(fig, "title", 0, 100, identity, sequenceFetcher=fetcher) fig.set_yticks.assert_called_with([])
def testTitle(self): """ A L{_FeatureAdder} must set the title of its figure. """ fetcher = lambda title, db='database': None featureAdder = _FeatureAdder() fig = plt.subplot(111) fig.set_title = MagicMock() featureAdder.add(fig, 'title', 0, 100, sequenceFetcher=fetcher) fig.set_title.assert_called_with('Target sequence features', fontsize=16)
def testYTicks(self): """ A L{_FeatureAdder} must set the title of its figure. """ def fetcher(title, db='database'): return None featureAdder = _FeatureAdder() fig = plt.subplot(111) fig.set_yticks = MagicMock() featureAdder.add(fig, 'title', 0, 100, sequenceFetcher=fetcher) fig.set_yticks.assert_called_with([])
def testYTicks(self): """ A L{_FeatureAdder} must set the title of its figure. """ def fetcher(title, db='database'): return None featureAdder = _FeatureAdder() fig = plt.subplot(111, label=_randomLabel()) fig.set_yticks = MagicMock() featureAdder.add(fig, 'title', 0, 100, sequenceFetcher=fetcher) fig.set_yticks.assert_called_with([])
def testTitle(self): """ A L{_FeatureAdder} must set the title of its figure. """ def fetcher(title, db='database'): return None featureAdder = _FeatureAdder() fig = plt.subplot(111) fig.set_title = MagicMock() featureAdder.add(fig, 'title', 0, 100, sequenceFetcher=fetcher) fig.set_title.assert_called_with('Target sequence features', fontsize=16)
def testOffline(self): """ If the sequence fetcher used by a L{_FeatureAdder} returns C{None}, the C{add} method of the L{_FeatureAdder} must return C{None}. The C{text} and C{axis} methods on the fig must both be called correctly. """ fetcher = lambda title, db="database": None featureAdder = _FeatureAdder() fig = plt.subplot(111) fig.text = MagicMock() fig.axis = MagicMock() featureAdder.add(fig, "title", 0, 300, identity, sequenceFetcher=fetcher) fig.text.assert_called_with(100, 0, "You (or Genbank) appear to be offline.", fontsize=20) fig.axis.assert_called_with([0, 300, -1, 1])
def testOffline(self): """ If the sequence fetcher used by a L{_FeatureAdder} returns C{None}, the C{add} method of the L{_FeatureAdder} must return C{None}. The C{text} and C{axis} methods on the fig must both be called correctly. """ fetcher = lambda title, db='database': None featureAdder = _FeatureAdder() fig = plt.subplot(111) fig.text = MagicMock() fig.axis = MagicMock() featureAdder.add(fig, 'title', 0, 300, sequenceFetcher=fetcher) fig.text.assert_called_with(100, 0, 'You (or Genbank) appear to be offline.', fontsize=20) fig.axis.assert_called_with([0, 300, -1, 1])
def testOneFeatureRaisesNotImplementedError(self): """ If the sequence fetcher used by a L{_FeatureAdder} returns a feature, the C{add} method must raise C{NotImplementedError} because the C{_displayFeatures} method is not implemented. """ def fetcher(title, db='database'): location = FeatureLocation(100, 200) feature = SeqFeature(type='site', qualifiers={'a': ['b']}, location=location) return SeqRecord(None, features=[feature]) featureAdder = _FeatureAdder() featureAdder.WANTED_TYPES = ('site',) fig = plt.subplot(111) self.assertRaises(NotImplementedError, featureAdder.add, fig, 'title', 0, 300, sequenceFetcher=fetcher)
def testOneFeatureRaisesNotImplementedError(self): """ If the sequence fetcher used by a L{_FeatureAdder} returns a feature, the C{add} method must raise C{NotImplementedError} because the C{_displayFeatures} method is not implemented. """ def fetcher(title, db="database"): subfeature = SeqFeature(type="region", qualifiers={"a": ["b"]}) feature = SeqFeature(type="site", qualifiers={"a": ["b"]}, sub_features=[subfeature]) return SeqRecord(None, features=[feature]) featureAdder = _FeatureAdder() featureAdder.WANTED_TYPES = ("site",) fig = plt.subplot(111) self.assertRaises( NotImplementedError, featureAdder.add, fig, "title", 0, 300, identity, sequenceFetcher=fetcher )
def testNoFeatures(self): """ If the sequence fetcher used by a L{_FeatureAdder} returns no features the C{text} and C{axis} methods on the fig must both be called correctly and the C{add} method must return C{[]}. """ fetcher = lambda title, db='database': SeqRecord(None) featureAdder = _FeatureAdder() featureAdder.WANTED_TYPES = ('site',) fig = plt.subplot(111) fig.text = MagicMock() fig.axis = MagicMock() result = featureAdder.add(fig, 'title', 0, 300, sequenceFetcher=fetcher) fig.text.assert_called_with(0.5, 0.5, 'No features found', horizontalalignment='center', verticalalignment='center', transform=ANY, fontsize=20) fig.axis.assert_called_with([0, 300, -1, 1]) self.assertEqual([], result)