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 all commits
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
21 changes: 21 additions & 0 deletions napalm_base/test/getters.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from itertools import zip_longest

import inspect
from inspect import ArgSpec
import json

import pytest
Expand Down Expand Up @@ -122,6 +123,21 @@ 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)
# 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 +153,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