Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make mockable backend for IO #50

Open
Zluurk opened this issue Oct 11, 2017 · 0 comments
Open

Make mockable backend for IO #50

Zluurk opened this issue Oct 11, 2017 · 0 comments

Comments

@Zluurk
Copy link
Collaborator

Zluurk commented Oct 11, 2017

For all IO:

  • Http request
  • Ftp request
  • File
  • MLLP
  • Futures IO
  • ...

We should create a unified backend that can be used by user defined nodes and allow intelligent mock.

With such backend we can easily test a channel without mock the whole node and be sure that all data are correctly read from node.

For example with http request backend with should be able to specify a response when we have a specific request.

Another example: file backend should be memory only to avoid writing file by mistake.

For file backend we can imagine something like that:

class FileBackend():
    async def open(self, path, mode):
        if in_test_mode():
            # TODO should verify file don't previously exists
            # or mock is defined especially for this path
            mocked_file = StringIO()
            self.open_files.append({
                'path': path,
                'mode': mode,
                'file': mocked_file
            )
            return mocked_file
        else:
            return open(path, mode)

This mock should be used for every file modification in pypeman.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant