def test_logs_on_schema_extraction(self):
workdir = self.useFixture(fixtures.TempDir())
fake_logger = self.useFixture(fixtures.FakeLogger())
good_path = os.path.join(workdir.path, 'my.py')
with open(good_path, 'w') as f:
f.write(dedent(
"""
service = AcceptableService('vendor')
root_api = service.api('/', 'root')
@root_api.view(introduced_at='1.0')
def my_view():
pass
"""))
[schema] = _build_doubles.extract_schemas_from_file(good_path)
self.assertEqual('root', schema.view_name)
self.assertEqual('1.0', schema.version)
self.assertEqual(['GET'], schema.methods)
self.assertEqual(None, schema.input_schema)
self.assertEqual(None, schema.output_schema)
self.assertThat(
fake_logger.output,
Contains('Extracting schemas from %s' % good_path))
self.assertThat(
fake_logger.output,
Contains('Extracted 1 schema'))
# To support testing, we need a version of ArgumentParser that doesn't call
# sys.exit on error, but rather throws an exception, so we can catch that in
# our tests:
评论列表
文章目录