本文整理汇总了Python中awscli.topictags.TopicTagDB类的典型用法代码示例。如果您正苦于以下问题:Python TopicTagDB类的具体用法?Python TopicTagDB怎么用?Python TopicTagDB使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TopicTagDB类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ProviderHelpCommand
class ProviderHelpCommand(HelpCommand):
"""Implements top level help command.
This is what is called when ``aws help`` is run.
"""
EventHandlerClass = ProviderDocumentEventHandler
def __init__(self, session, command_table, arg_table,
description, synopsis, usage):
HelpCommand.__init__(self, session, None,
command_table, arg_table)
self.description = description
self.synopsis = synopsis
self.help_usage = usage
self._subcommand_table = None
self._topic_tag_db = None
self._related_items = ['aws help topics']
@property
def event_class(self):
return 'aws'
@property
def name(self):
return 'aws'
@property
def subcommand_table(self):
if self._subcommand_table is None:
if self._topic_tag_db is None:
self._topic_tag_db = TopicTagDB()
self._topic_tag_db.load_json_index()
self._subcommand_table = self._create_subcommand_table()
return self._subcommand_table
def _create_subcommand_table(self):
subcommand_table = {}
# Add the ``aws help topics`` command to the ``topic_table``
topic_lister_command = TopicListerCommand(self.session)
subcommand_table['topics'] = topic_lister_command
topic_names = self._topic_tag_db.get_all_topic_names()
# Add all of the possible topics to the ``topic_table``
for topic_name in topic_names:
topic_help_command = TopicHelpCommand(self.session, topic_name)
subcommand_table[topic_name] = topic_help_command
return subcommand_table
示例2: test_get_tag_value_all_tags
def test_get_tag_value_all_tags(self):
topic_name = 'topic-name-1'
tag_dict = {
topic_name: {
'title': ['My First Topic Title'],
'description': ['This describes my first topic'],
'category': ['General Topics'],
'related command': ['aws s3'],
'related topic': ['topic-name-2']
}
}
self.topic_tag_db = TopicTagDB(tag_dict)
# Check the title get tag value
value = self.topic_tag_db.get_tag_value(topic_name, 'title')
self.assertEqual(value, ['My First Topic Title'])
# Check the description get tag value
value = self.topic_tag_db.get_tag_value(topic_name, 'description')
self.assertEqual(value, ['This describes my first topic'])
# Check the category get tag value
value = self.topic_tag_db.get_tag_value(topic_name, 'category')
self.assertEqual(value, ['General Topics'])
# Check the related command get tag value
value = self.topic_tag_db.get_tag_value(topic_name,
'related command')
self.assertEqual(value, ['aws s3'])
# Check the related topic get tag value
value = self.topic_tag_db.get_tag_value(topic_name, 'related topic')
self.assertEqual(value, ['topic-name-2'])
示例3: test_load_and_save_json_index
def test_load_and_save_json_index(self):
tag_dict = {
'topic-name-1': {
'title': ['My First Topic Title'],
'description': ['This describes my first topic'],
'category': ['General Topics', 'S3'],
'related command': ['aws s3'],
'related topic': ['topic-name-2']
},
'topic-name-2': {
'title': ['My Second Topic Title'],
'description': ['This describes my second topic'],
'category': ['General Topics'],
'related topic': ['topic-name-1']
}
}
json_index = self.file_creator.create_file('index.json', '')
# Create a JSON index to be loaded.
tag_json = json.dumps(tag_dict, indent=4, sort_keys=True)
with open(json_index, 'w') as f:
f.write(tag_json)
# Load the JSON index.
self.topic_tag_db = TopicTagDB(index_file=json_index)
self.topic_tag_db.load_json_index()
# Write the loaded json to disk and ensure it is as expected.
saved_json_index = self.file_creator.create_file('index2.json', '')
self.topic_tag_db.index_file = saved_json_index
self.topic_tag_db.save_to_json_index()
with open(saved_json_index, 'r') as f:
self.assertEqual(f.read(), tag_json)
示例4: subcommand_table
def subcommand_table(self):
if self._subcommand_table is None:
if self._topic_tag_db is None:
self._topic_tag_db = TopicTagDB()
self._topic_tag_db.load_json_index()
self._subcommand_table = self._create_subcommand_table()
return self._subcommand_table
示例5: assert_json_index
def assert_json_index(self, file_paths, reference_tag_dict):
"""Asserts the scanned tags by checking the saved JSON index"""
json_index = self.file_creator.create_file('index.json', '')
self.topic_tag_db = TopicTagDB(index_file=json_index)
self.topic_tag_db.scan(file_paths)
self.topic_tag_db.save_to_json_index()
with open(json_index, 'r') as f:
saved_index = json.loads(f.read())
self.assertEqual(saved_index, reference_tag_dict)
示例6: topic_query_with_non_existant_tag
def topic_query_with_non_existant_tag(self):
tag_dict = {
'topic-name-1': {
'category': ['foo']
}
}
self.topic_tag_db = TopicTagDB(tag_dict)
query_dict = self.topic_tag_db.query(':bar:')
self.assertEqual(query_dict, {})
示例7: test_query_tag_multi_values
def test_query_tag_multi_values(self):
tag_dict = {
'topic-name-1': {
'related topic': ['foo', 'bar']
}
}
self.topic_tag_db = TopicTagDB(tag_dict)
query_dict = self.topic_tag_db.query('related topic')
self.assertEqual(query_dict,
{'foo': ['topic-name-1'], 'bar': ['topic-name-1']})
示例8: test_get_tag_single_value_exception
def test_get_tag_single_value_exception(self):
topic_name = 'topic-name-1'
tag_dict = {
topic_name: {
'title': ['foo', 'bar']
}
}
self.topic_tag_db = TopicTagDB(tag_dict)
with self.assertRaises(ValueError):
self.topic_tag_db.get_tag_single_value('topic-name-1', 'title')
示例9: test_get_tag_single_value
def test_get_tag_single_value(self):
topic_name = 'topic-name-1'
tag_dict = {
topic_name: {
'title': ['foo']
}
}
self.topic_tag_db = TopicTagDB(tag_dict)
value = self.topic_tag_db.get_tag_single_value('topic-name-1', 'title')
self.assertEqual(value, 'foo')
示例10: test_get_tag_no_exist_use_default
def test_get_tag_no_exist_use_default(self):
topic_name = 'topic-name-1'
tag_dict = {
topic_name: {
'related topic': ['foo']
}
}
self.topic_tag_db = TopicTagDB(tag_dict)
value = self.topic_tag_db.get_tag_value('no-exist', ':foo:', [])
self.assertEqual(value, [])
示例11: test_get_tag_no_exist_tag
def test_get_tag_no_exist_tag(self):
topic_name = 'topic-name-1'
tag_dict = {
topic_name: {
'related topic': ['foo']
}
}
self.topic_tag_db = TopicTagDB(tag_dict)
value = self.topic_tag_db.get_tag_value(topic_name, ':foo:')
self.assertEqual(value, None)
示例12: test_get_tag_multi_value
def test_get_tag_multi_value(self):
topic_name = 'topic-name-1'
tag_dict = {
topic_name: {
'related topic': ['foo', 'bar']
}
}
self.topic_tag_db = TopicTagDB(tag_dict)
# Check the related topic get tag value
value = self.topic_tag_db.get_tag_value(topic_name, 'related topic')
self.assertEqual(value, ['foo', 'bar'])
示例13: test_get_all_topic_source_files
def test_get_all_topic_source_files(self):
source_files = []
topic_dir = self.file_creator.rootdir
self.topic_tag_db = TopicTagDB(topic_dir=topic_dir)
for i in range(5):
topic_name = 'topic-name-' + str(i)
source_files.append(self.file_creator.create_file(topic_name, ''))
self.assertCountEqual(
self.topic_tag_db.get_all_topic_src_files(),
source_files
)
示例14: test_get_all_topic_source_files_ignore_hidden
def test_get_all_topic_source_files_ignore_hidden(self):
topic_filename = 'mytopic'
hidden_filename = '.' + topic_filename
source_files = []
source_files.append(self.file_creator.create_file(topic_filename, ''))
self.file_creator.create_file(hidden_filename, '')
topic_dir = self.file_creator.rootdir
self.topic_tag_db = TopicTagDB(topic_dir=topic_dir)
self.assertCountEqual(
self.topic_tag_db.get_all_topic_src_files(),
source_files
)
示例15: test_query_multiple_topics
def test_query_multiple_topics(self):
tag_dict = {
'topic-name-1': {
'category': ['foo']
},
'topic-name-2': {
'category': ['bar']
}
}
self.topic_tag_db = TopicTagDB(tag_dict)
query_dict = self.topic_tag_db.query('category')
self.assertEqual(query_dict,
{'foo': ['topic-name-1'], 'bar': ['topic-name-2']})