# Path: chopsticks/helpers.py
# def output_lines(*args, **kwargs):
#     """Return the lines of output from the given command args."""
#     return check_output(*args, **kwargs).splitlines()
# 
# Path: chopsticks/tunnel.py
# class Docker(SubprocessTunnel):
#     """A tunnel connected to a throwaway Docker container.
# 
#     :param name: The name of the Docker instance to create.
#     :param image: The Docker image to launch. By default, download and run an
#                   `official Docker Python image`__ corresponding to the
#                   running Python version. `Official images are curated by
#                   Docker`__.
#     :param rm: If true, destroy the container when the tunnel is closed.
# 
#     .. __: https://hub.docker.com/_/python/
#     .. __: https://docs.docker.com/docker-hub/official_repos/
# 
#     """
#     #: For the standard Python docker images, Python is not installed as
#     #: /usr/bin/python[23]
#     python2 = 'python'
#     python3 = 'python3'
# 
#     pyver = '{0}.{1}'.format(*sys.version_info)
# 
#     def __init__(self, name, image='python:' + pyver, rm=True):
#         self.host = name
#         self.image = image
#         self.rm = rm
#         super(Docker, self).__init__()
# 
#     def cmd_args(self):
#         base = super(Docker, self).cmd_args()
#         args = []
#         if self.rm:
#             args.append('--rm')
# 
#         return [
#             'docker',
#             'run',
#             '-i',
#             '--name',
#             self.host,
#         ] + args + [self.image] + base
# 
# Path: chopsticks/facts.py
# def python_version(short=False):
#     """Get the Python version."""
#     if short:
#         return list(sys.version_info[:2])
#     return list(sys.version_info)


import time
import random
import sys
import os
import tempfile
import hashlib
    import pkgutil
from unittest import TestCase
from chopsticks.helpers import output_lines
from chopsticks.tunnel import Docker
from chopsticks.facts import python_version
    from hashlib import sha1
    def test_fetch(self):
        """We can fetch a file from a remote Docker."""
        local = tempfile.mktemp()
        res = self.tunnel.fetch(
            remote_path=self.GPL,
            local_path=local
        )
        with open(local, 'rb') as f:
            data = f.read()
        self.assertEqual(res, {
            'local_path': local,
            'remote_path': '/usr/share/common-licenses/GPL',
            'sha1sum': hashlib.sha1(data).hexdigest(),
            'size': len(data)
        })

    def test_put(self):
        """We can copy a file to a remote Docker."""
        res = self.tunnel.put(
            local_path=self.GPL,
            remote_path='/tmp/gpl',
            mode=0o760
        )
        with open(self.GPL, 'rb') as f:
            data = f.read()
        self.assertEqual(res, {
            'remote_path': '/tmp/gpl',
            'sha1sum': hashlib.sha1(data).hexdigest(),
            'size': len(data)
        })

# Path: chopsticks/helpers.py
# def output_lines(*args, **kwargs):
#     """Return the lines of output from the given command args."""
#     return check_output(*args, **kwargs).splitlines()
# 
# Path: chopsticks/tunnel.py
# class Docker(SubprocessTunnel):
#     """A tunnel connected to a throwaway Docker container.
# 
#     :param name: The name of the Docker instance to create.
#     :param image: The Docker image to launch. By default, download and run an
#                   `official Docker Python image`__ corresponding to the
#                   running Python version. `Official images are curated by
#                   Docker`__.
#     :param rm: If true, destroy the container when the tunnel is closed.
# 
#     .. __: https://hub.docker.com/_/python/
#     .. __: https://docs.docker.com/docker-hub/official_repos/
# 
#     """
#     #: For the standard Python docker images, Python is not installed as
#     #: /usr/bin/python[23]
#     python2 = 'python'
#     python3 = 'python3'
# 
#     pyver = '{0}.{1}'.format(*sys.version_info)
# 
#     def __init__(self, name, image='python:' + pyver, rm=True):
#         self.host = name
#         self.image = image
#         self.rm = rm
#         super(Docker, self).__init__()
# 
#     def cmd_args(self):
#         base = super(Docker, self).cmd_args()
#         args = []
#         if self.rm:
#             args.append('--rm')
# 
#         return [
#             'docker',
#             'run',
#             '-i',
#             '--name',
#             self.host,
#         ] + args + [self.image] + base
# 
# Path: chopsticks/facts.py
# def python_version(short=False):
#     """Get the Python version."""
#     if short:
#         return list(sys.version_info[:2])
#     return list(sys.version_info)


# Path: tests/test_tunnels.py
import time
import random
import sys
import os
import tempfile
import hashlib
    import pkgutil
from unittest import TestCase
from chopsticks.helpers import output_lines
from chopsticks.tunnel import Docker
from chopsticks.facts import python_version
    from hashlib import sha1

    def test_fetch(self):
        """We can fetch a file from a remote Docker."""
        local = tempfile.mktemp()
        res = self.tunnel.fetch(
            remote_path=self.GPL,
            local_path=local
        )
        with open(local, 'rb') as f:
            data = f.read()
        self.assertEqual(res, {
            'local_path': local,
            'remote_path': '/usr/share/common-licenses/GPL',
            'sha1sum': hashlib.sha1(data).hexdigest(),
            'size': len(data)
        })

    def test_put(self):
        """We can copy a file to a remote Docker."""
        res = self.tunnel.put(
            local_path=self.GPL,
            remote_path='/tmp/gpl',
            mode=0o760
        )
        with open(self.GPL, 'rb') as f:
            data = f.read()
        self.assertEqual(res, {
            'remote_path': '/tmp/gpl',
            'sha1sum': hashlib.sha1(data).hexdigest(),
            'size': len(data)
        })

        out = self.tunnel.call(output_lines, ['ls', '-l', '/tmp'])