"""Make sure that arguments of open/read/write don't diverge."""

import soundfile as sf
from inspect import getargspec


init = getargspec(sf.SoundFile.__init__)
read_function = getargspec(sf.read)
read_method = getargspec(sf.SoundFile.read)
write_function = getargspec(sf.write)
blocks_function = getargspec(sf.blocks)
blocks_method = getargspec(sf.SoundFile.blocks)


def defaults(spec):
    return dict(zip(reversed(spec.args), reversed(spec.defaults)))


def remove_items(collection, subset):
    """From a collection of defaults, remove a subset and return the rest."""
    the_rest = collection.copy()
    for arg, default in subset.items():
        assert (arg, the_rest[arg]) == (arg, default)
        del the_rest[arg]
    return the_rest


def test_read_defaults():
    func_defaults = defaults(read_function)
    meth_defaults = defaults(read_method)
    init_defaults = defaults(init)

    del init_defaults['mode']  # mode is always 'r'

    del func_defaults['start']
    del func_defaults['stop']

    # Same default values as SoundFile.__init__() and SoundFile.read():
    for spec in init_defaults, meth_defaults:
        func_defaults = remove_items(func_defaults, spec)

    assert not func_defaults  # No more arguments should be left


def test_write_defaults():
    write_defaults = defaults(write_function)
    init_defaults = defaults(init)

    # Same default values as SoundFile.__init__()
    init_defaults = remove_items(init_defaults, write_defaults)

    del init_defaults['mode']  # mode is always 'x' or 'w'
    del init_defaults['channels']  # Inferred from data
    del init_defaults['samplerate']  # Obligatory in write()
    assert not init_defaults  # No more arguments should be left


def test_if_blocks_function_and_method_have_same_defaults():
    func_defaults = defaults(blocks_function)
    meth_defaults = defaults(blocks_method)
    init_defaults = defaults(init)

    del func_defaults['start']
    del func_defaults['stop']
    del init_defaults['mode']

    for spec in init_defaults, meth_defaults:
        func_defaults = remove_items(func_defaults, spec)

    assert not func_defaults


def test_order_of_blocks_arguments():
    # Only the first few are checked
    meth_args = blocks_method.args[1:]  # remove 'self'
    meth_args[3:3] = ['start', 'stop']
    assert blocks_function.args[:10] == ['file'] + meth_args

@@ -59,16 +59,30 @@
 ge.%22%22%22%0A%0A
+import pytest%0A
 import s
@@ -100,375 +100,328 @@
  sf%0A
-from inspect import getargspec%0A%0A%0Ainit = getargspec(sf.SoundFile.__init__)%0Aread_function = getargspec(sf.read)%0Aread_method = getargspec(sf.SoundFile.read)%0Awrite_function = getargspec(sf.write)%0Ablocks_function = getargspec(sf.blocks)%0Ablocks_method = getargspec(sf.SoundFile.blocks)%0A%0A%0Adef defaults(spec):%0A    return dict(zip(reversed(spec.args), reversed(spec.defaults))
+import sys%0A%0A%0Apytestmark = pytest.mark.skipif(sys.version_info %3C (3, 3),%0A                                reason=%22signature module requires Python 3.3%22)%0A%0A%0Adef defaults(func):%0A    from inspect import signature%0A    return dict((k, v) for k, v in signature(func).parameters.items()%0A                if v.default is not v.empty
 )%0A%0A%0A
@@ -577,28 +577,27 @@
     for 
-arg, default
+name, param
  in subs
@@ -624,19 +624,20 @@
 assert (
-arg
+name
 , the_re
@@ -643,23 +643,39 @@
 est%5B
-arg%5D) == (arg, 
+name%5D.default) == (name, param.
 defa
@@ -700,19 +700,20 @@
 he_rest%5B
-arg
+name
 %5D%0A    re
@@ -787,21 +787,15 @@
 lts(
+sf.
 read
-_function
 )%0A  
@@ -825,18 +825,24 @@
 lts(
-read_metho
+sf.SoundFile.rea
 d)%0A 
@@ -861,36 +861,53 @@
 ults = defaults(
+sf.SoundFile.__
 init
+__
 )%0A%0A    del init_
@@ -1313,22 +1313,16 @@
 lts(
+sf.
 write
-_function
 )%0A  
@@ -1344,28 +1344,45 @@
  = defaults(
+sf.SoundFile.__
 init
+__
 )%0A%0A    # Sam
@@ -1820,31 +1820,25 @@
 efaults(
+sf.
 blocks
-_function
 )%0A    me
@@ -1860,29 +1860,35 @@
 efaults(
-blocks_method
+sf.SoundFile.blocks
 )%0A    in
@@ -1910,20 +1910,37 @@
 efaults(
+sf.SoundFile.__
 init
+__
 )%0A%0A    d
@@ -2208,163 +2208,237 @@
     
-# Only the first few are checked%0A    meth_args = blocks_method.args%5B1:%5D  # remove 'self'%0A    meth_args%5B3:3%5D = %5B'start', 'stop'%5D%0A    assert blocks_function.
+from inspect import signature%0A%0A    # remove 'self':%0A    meth_args = list(signature(sf.SoundFile.blocks).parameters)%5B1:%5D%0A    meth_args%5B3:3%5D = %5B'start', 'stop'%5D%0A    func_args = list(signature(sf.blocks).parameters)%0A    assert func_
 args

Use inspect.signature instead of inspect.getargspec