Rev 11: PluginInfo can now output a python representation of itself. in http://people.canonical.com/~robertc/baz2.0/plugins/plugin_info/trunk
Robert Collins
robertc at robertcollins.net
Mon Mar 1 01:16:01 GMT 2010
At http://people.canonical.com/~robertc/baz2.0/plugins/plugin_info/trunk
------------------------------------------------------------
revno: 11
revision-id: robertc at robertcollins.net-20100301011555-y7ky6a0bgi8ry1qi
parent: robertc at robertcollins.net-20100301005750-wjhzzkrv9dg0i0jn
committer: Robert Collins <robertc at robertcollins.net>
branch nick: trunk
timestamp: Mon 2010-03-01 12:15:55 +1100
message:
PluginInfo can now output a python representation of itself.
=== modified file 'NEWS'
--- a/NEWS 2010-03-01 00:57:50 +0000
+++ b/NEWS 2010-03-01 01:15:55 +0000
@@ -28,6 +28,9 @@
INTERNALS:
+ * PluginInfo can now output a python representation of itself.
+ (Robert Collins)
+
* New class ``extract.PluginInfo`` for reporting extraction results.
(Robert Collins)
=== modified file 'extract.py'
--- a/extract.py 2010-03-01 00:57:50 +0000
+++ b/extract.py 2010-03-01 01:15:55 +0000
@@ -1,5 +1,5 @@
# plugin_info, a plugin for working with information about plugins.
-# Copyright (C) 2008 Canonical Limited.
+# Copyright (C) 2008, 2010 Canonical Limited.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as published
@@ -124,3 +124,20 @@
'transports(%s).'
% (self.name, version_string, self.location, command_string, control_string,
checkout_string, branch_string, repository_string, transports_string))
+
+ def to_python(self):
+ """Represent this PluginInfo as a python source fragment."""
+ result = []
+ result.append('%s = PluginInfo()\n' % self.name)
+ result.append('%s.name = %s\n' % (self.name, self.name))
+ result.append('%s.location = %s\n' % (self.name, self.location))
+ result.append('%s.version_info = %s\n' % (self.name, self.version_info))
+ result.append('%s.minimum_bzr_version = %s\n' % (self.name, self.minimum_bzr_version))
+ result.append('%s.maximum_bzr_version = %s\n' % (self.name, self.maximum_bzr_version))
+ result.append('%s.commands = %s\n' % (self.name, self.commands))
+ result.append('%s.control_formats = %s\n' % (self.name, self.control_formats))
+ result.append('%s.checkout_formats = %s\n' % (self.name, self.checkout_formats))
+ result.append('%s.branch_formats = %s\n' % (self.name, self.branch_formats))
+ result.append('%s.repository_formats = %s\n' % (self.name, self.repository_formats))
+ result.append('%s.transports = %s\n' % (self.name, self.transports))
+ return ''.join(result)
=== modified file 'tests/__init__.py'
--- a/tests/__init__.py 2008-02-29 19:00:41 +0000
+++ b/tests/__init__.py 2010-03-01 01:15:55 +0000
@@ -1,5 +1,5 @@
# plugin_info, a plugin for working with information about plugins.
-# Copyright (C) 2006 Canonical Limited.
+# Copyright (C) 2008 Canonical Limited.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as published
=== modified file 'tests/test_extract.py'
--- a/tests/test_extract.py 2010-03-01 00:57:50 +0000
+++ b/tests/test_extract.py 2010-03-01 01:15:55 +0000
@@ -26,6 +26,21 @@
class TestPluginInfo(TestCaseWithTransport):
+ def sample_plugin(self):
+ plugin = PluginInfo()
+ plugin.name = "plugin_info"
+ plugin.commands = ["foo"]
+ plugin.version_info = (1, 2, 0, 'dev', 0)
+ plugin.minimum_bzr_version = (1, 0, 0)
+ plugin.maximum_bzr_version = None
+ plugin.control_formats = {"svn":{"ignored":None}}
+ plugin.checkout_formats = {"signature":"dirstate"}
+ plugin.branch_formats = {"signature":"format 6"}
+ plugin.repository_formats = {"signature":"packs"}
+ plugin.transports = ["hg+ssh://"]
+ plugin.location = "http://bazaar-vcs.org/plugin-info/"
+ return plugin
+
def test_construct(self):
plugin = PluginInfo()
@@ -43,21 +58,27 @@
self.assertEqual({}, plugin.repository_formats)
def test_str(self):
- plugin = PluginInfo()
- plugin.name = "plugin_info"
- plugin.commands = ["foo"]
- plugin.version_info = (1, 2, 0, 'dev', 0)
- plugin.minimum_bzr_version = (1, 0, 0)
- plugin.maximum_bzr_version = None
- plugin.control_formats = {"svn":{"ignored":None}}
- plugin.checkout_formats = {"signature":"dirstate"}
- plugin.branch_formats = {"signature":"format 6"}
- plugin.repository_formats = {"signature":"packs"}
- plugin.transports = ["hg+ssh://"]
- plugin.location = "http://bazaar-vcs.org/plugin-info/"
+ plugin = self.sample_plugin()
self.assertEqual('plugin_info(1.2.0dev0) from http://bazaar-vcs.org/plugin-info/ supplies commands("foo"), control formats("svn"), checkout formats("dirstate"), branch formats("format 6"), repository formats("packs"), transports("hg+ssh://").',
str(plugin))
+ def test_python(self):
+ # A plugin info can be turned into a python source fragment.
+ plugin = self.sample_plugin()
+ self.assertEqual("""plugin_info = PluginInfo()
+plugin_info.name = plugin_info
+plugin_info.location = http://bazaar-vcs.org/plugin-info/
+plugin_info.version_info = (1, 2, 0, 'dev', 0)
+plugin_info.minimum_bzr_version = (1, 0, 0)
+plugin_info.maximum_bzr_version = None
+plugin_info.commands = ['foo']
+plugin_info.control_formats = {'svn': {'ignored': None}}
+plugin_info.checkout_formats = {'signature': 'dirstate'}
+plugin_info.branch_formats = {'signature': 'format 6'}
+plugin_info.repository_formats = {'signature': 'packs'}
+plugin_info.transports = ['hg+ssh://']
+""", plugin.to_python())
+
def test___eq__(self):
plugin_expected = PluginInfo()
plugin_expected.name = "1"
More information about the bazaar-commits
mailing list