コード例 #1
0
ファイル: test_runtime.py プロジェクト: zsotesz81/aws-sam-cli
    def test_must_unzip_posix(self, os_mock, unzip_mock, tempfile_mock):
        inputpath = "somepath"
        tmpdir = "/tmp/dir"
        realpath = "/foo/bar/tmp/dir/code.zip"

        tempfile_mock.mkdtemp.return_value = tmpdir
        os_mock.path.realpath.return_value = realpath
        os_mock.name = 'posix'

        output = _unzip_file(inputpath)
        self.assertEquals(output, realpath)

        tempfile_mock.mkdtemp.assert_called_with()
        unzip_mock.assert_called_with(inputpath, tmpdir)  # unzip files to temporary directory
        os_mock.path.realpath(tmpdir)  # Return the real path of temporary directory
        os_mock.chmod.assert_called_with(tmpdir, 0o755)  # Assert we do chmod the temporary directory
コード例 #2
0
    def test_must_unzip(self, os_mock, zipfile_mock, tempfile_mock):
        inputpath = "somepath"
        tmpdir = "/tmp/dir"
        realpath = "/foo/bar/tmp/dir/code.zip"
        zipref = Mock()

        tempfile_mock.mkdtemp.return_value = tmpdir
        zipfile_mock.ZipFile.return_value = zipref
        os_mock.path.realpath.return_value = realpath

        output = _unzip_file(inputpath)
        self.assertEquals(output, realpath)

        tempfile_mock.mkdtemp.assert_called_with()
        zipfile_mock.ZipFile.assert_called_with(inputpath,
                                                'r')  # Open file for reading
        zipref.extractall.assert_called_with(
            tmpdir)  # unzip files to temporary directory
        os_mock.path.realpath(
            tmpdir)  # Return the real path of temporary directory