def test_base_run(base_config): h = harvest.Harvester(['-'], base_config) h.gobble = fake_gobble assert isinstance(h.run(), collections_abc.Iterator) assert list(h.run()) == [('-', 42)] h.gobble = fake_gobble_raising assert list(h.run()) == [('-', {'error': 'mystr'})]
def test_base_iter_filenames(base_config, mocker): iter_mock = mocker.patch('radon.cli.harvest.iter_filenames') h = harvest.Harvester([], base_config) h._iter_filenames() iter_mock.assert_called_with([], base_config.exclude, base_config.ignore)
def test_run(self): h = harvest.Harvester(['-'], self.config) h.gobble = fake_gobble self.assertTrue(isinstance(h.run(), collections.Iterator)) self.assertEqual(list(h.run()), [('-', 42)]) h.gobble = fake_gobble_raising self.assertEqual(list(h.run()), [('-', {'error': 'mystr'})])
def test_base_results(base_config): h = harvest.Harvester([], base_config) h.run = fake_run results = h.results assert isinstance(results, collections_abc.Iterator) assert list(results) == [{'file-0': 0}, {'file-1': 1}, {'file-2': 4}] assert not isinstance(h.results, collections_abc.Iterator) assert isinstance(h.results, collections_abc.Iterable) assert isinstance(h.results, list)
def test_results(self): h = harvest.Harvester([], self.config) h.run = fake_run results = h.results self.assertTrue(isinstance(results, collections.Iterator)) self.assertEqual(list(results), [{ 'file-0': 0 }, { 'file-1': 1 }, { 'file-2': 4 }]) self.assertFalse(isinstance(h.results, collections.Iterator)) self.assertTrue(isinstance(h.results, collections.Iterable)) self.assertTrue(isinstance(h.results, list))
def test_base_to_terminal_not_implemented(base_config): h = harvest.Harvester([], base_config) with pytest.raises(NotImplementedError): h.to_terminal()
def test_base_as_xml_not_implemented(base_config): h = harvest.Harvester([], base_config) with pytest.raises(NotImplementedError): h.as_xml()
def test_base_gobble_not_implemented(base_config): h = harvest.Harvester([], base_config) with pytest.raises(NotImplementedError): h.gobble(None)
def test_base_as_json(base_config): h = harvest.Harvester([], base_config) h._results = {'filename': {'complexity': 2}} assert h.as_json() == '{"filename": {"complexity": 2}}'
def test_to_terminal_not_implemented(self): h = harvest.Harvester([], self.config) self.assertRaises(NotImplementedError, h.to_terminal)
def test_as_xml_not_implemented(self): h = harvest.Harvester([], self.config) self.assertRaises(NotImplementedError, h.as_xml)
def test_gobble_not_implemented(self): h = harvest.Harvester([], self.config) self.assertRaises(NotImplementedError, h.gobble, None)
def test_iter_filenames(self, iter_mock): h = harvest.Harvester([], self.config) h._iter_filenames() iter_mock.assert_called_with([], self.config.exclude, self.config.ignore)
def test_as_json(self): h = harvest.Harvester([], self.config) h._results = {'filename': {'complexity': 2}} self.assertEqual(h.as_json(), '{"filename": {"complexity": 2}}')