Skip to content
This repository has been archived by the owner on Sep 17, 2019. It is now read-only.

Add support for transition of signatures (to ease migration of methods) #239

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions napalm_base/test/getters.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,24 @@ class BaseTestGetters(object):

def test_method_signatures(self):
"""Test that all methods have the same signature."""

# Method signatures that are migrating from old to new state (temporary state)
transition = True
if transition:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand this :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes...that isn't very good...let me cleanup.

from inspect import ArgSpec
# napalm-base must match new; napalm-driver must match old (if not identical to base)
TRANSITION_SIGNATURES = {
'commit_config': {
'old': ArgSpec(args=['self'], varargs=None, keywords=None, defaults=None),
'new': ArgSpec(args=['self', 'confirmed'], varargs=None,
keywords=None, defaults=(0,)),
},
'commit_confirm': {
'old': 'Method does not exist in napalm_base',
'new': ArgSpec(args=['self'], varargs=None, keywords=None, defaults=None),
},
}

errors = {}
cls = self.driver
# Create fictional driver instance (py3 needs bound methods)
Expand All @@ -137,6 +155,11 @@ def test_method_signatures(self):
except AttributeError:
orig_spec = 'Method does not exist in napalm_base'
func_spec = inspect.getargspec(func)
if attr in TRANSITION_SIGNATURES.keys():
old_spec = TRANSITION_SIGNATURES[attr]['old']
new_spec = TRANSITION_SIGNATURES[attr]['new']
if orig_spec == new_spec and func_spec == old_spec:
continue
if orig_spec != func_spec:
errors[attr] = (orig_spec, func_spec)

Expand Down