
import os

from . import CallableDecorator


class FileReaderDecorator(CallableDecorator):
    """
    Decorator for SUTs that take input as a file path: saves the content of
    the failing test case.

    Moreover, the issue (if any) is also extended with the new ``'filename'``
    property containing the name of the test case (as received in the ``test``
    argument).

    **Example configuration snippet:**

        .. code-block:: ini

            [sut.foo]
            call=fuzzinator.call.SubprocessCall
            call.decorate(0)=fuzzionator.call.FileReaderDecorator

            [sut.foo.call]
            # assuming that foo takes one file as input specified on command line
            command=/home/alice/foo/bin/foo {test}
    """

    def decorator(self, **kwargs):
        def wrapper(fn):
            def reader(*args, **kwargs):
                issue = fn(*args, **kwargs)

                if issue is not None:
                    with open(issue['test'], 'rb') as f:
                        issue['filename'] = os.path.basename(issue['test'])
                        issue['test'] = f.read()

                return issue

            return reader
        return wrapper


import os

from . import CallableDecorator


class FileReaderDecorator(CallableDecorator):
    """
    Decorator for SUTs that take input as a file path: saves the content of
    the failing test case.

    Moreover, the issue (if any) is also extended with the new ``'filename'``
    property containing the name of the test case (as received in the ``test``
    argument).

    **Example configuration snippet:**

        .. code-block:: ini

            [sut.foo]
            call=fuzzinator.call.SubprocessCall
            call.decorate(0)=fuzzionator.call.FileReaderDecorator

            [sut.foo.call]
            # assuming that foo takes one file as input specified on command line
            command=/home/alice/foo/bin/foo {test}
    """

    def decorator(self, **kwargs):
        def wrapper(fn):
            def reader(*args, **kwargs):
                issue = fn(*args, **kwargs)

                if issue is not None:
                    with open(kwargs['test'], 'rb') as f:
                        issue['filename'] = os.path.basename(kwargs['test'])
                        issue['test'] = f.read()

                return issue

            return reader
        return wrapper

Fix test extraction in FileReaderDecorator.
Fix test extraction in FileReaderDecorator.

  
  import os
  
  from . import CallableDecorator
  
  
  class FileReaderDecorator(CallableDecorator):
      """
      Decorator for SUTs that take input as a file path: saves the content of
      the failing test case.
  
      Moreover, the issue (if any) is also extended with the new ``'filename'``
      property containing the name of the test case (as received in the ``test``
      argument).
  
      **Example configuration snippet:**
  
          .. code-block:: ini
  
              [sut.foo]
              call=fuzzinator.call.SubprocessCall
              call.decorate(0)=fuzzionator.call.FileReaderDecorator
  
              [sut.foo.call]
              # assuming that foo takes one file as input specified on command line
              command=/home/alice/foo/bin/foo {test}
      """
  
      def decorator(self, **kwargs):
          def wrapper(fn):
              def reader(*args, **kwargs):
                  issue = fn(*args, **kwargs)
  
                  if issue is not None:
-                     with open(issue['test'], 'rb') as f:
+                     with open(kwargs['test'], 'rb') as f:
-                         issue['filename'] = os.path.basename(issue['test'])
+                         issue['filename'] = os.path.basename(kwargs['test'])
                          issue['test'] = f.read()
  
                  return issue
  
              return reader
          return wrapper
  
Fix test extraction in FileReaderDecorator.
## Code Before:

import os

from . import CallableDecorator


class FileReaderDecorator(CallableDecorator):
    """
    Decorator for SUTs that take input as a file path: saves the content of
    the failing test case.

    Moreover, the issue (if any) is also extended with the new ``'filename'``
    property containing the name of the test case (as received in the ``test``
    argument).

    **Example configuration snippet:**

        .. code-block:: ini

            [sut.foo]
            call=fuzzinator.call.SubprocessCall
            call.decorate(0)=fuzzionator.call.FileReaderDecorator

            [sut.foo.call]
            # assuming that foo takes one file as input specified on command line
            command=/home/alice/foo/bin/foo {test}
    """

    def decorator(self, **kwargs):
        def wrapper(fn):
            def reader(*args, **kwargs):
                issue = fn(*args, **kwargs)

                if issue is not None:
                    with open(issue['test'], 'rb') as f:
                        issue['filename'] = os.path.basename(issue['test'])
                        issue['test'] = f.read()

                return issue

            return reader
        return wrapper

## Instruction:
Fix test extraction in FileReaderDecorator.
## Code After:

import os

from . import CallableDecorator


class FileReaderDecorator(CallableDecorator):
    """
    Decorator for SUTs that take input as a file path: saves the content of
    the failing test case.

    Moreover, the issue (if any) is also extended with the new ``'filename'``
    property containing the name of the test case (as received in the ``test``
    argument).

    **Example configuration snippet:**

        .. code-block:: ini

            [sut.foo]
            call=fuzzinator.call.SubprocessCall
            call.decorate(0)=fuzzionator.call.FileReaderDecorator

            [sut.foo.call]
            # assuming that foo takes one file as input specified on command line
            command=/home/alice/foo/bin/foo {test}
    """

    def decorator(self, **kwargs):
        def wrapper(fn):
            def reader(*args, **kwargs):
                issue = fn(*args, **kwargs)

                if issue is not None:
                    with open(kwargs['test'], 'rb') as f:
                        issue['filename'] = os.path.basename(kwargs['test'])
                        issue['test'] = f.read()

                return issue

            return reader
        return wrapper
