Skip to content

Commit

Permalink
Try using pyenv
Browse files Browse the repository at this point in the history
  • Loading branch information
joshfriend committed Mar 16, 2016
1 parent 2073137 commit 2ef390f
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 29 deletions.
1 change: 0 additions & 1 deletion .python-version

This file was deleted.

27 changes: 10 additions & 17 deletions .travis.yml
@@ -1,10 +1,11 @@
sudo: false

language: python
python:
- 2.7
- 3.4
- 3.5

env:
- PYTHON_VERSION=2.7.11
- PYTHON_VERSION=3.4.4
- PYTHON_VERSION=3.5.1

addons:
apt:
Expand All @@ -17,25 +18,17 @@ addons:
cache:
pip: true
directories:
- env
- $HOME/env
- $HOME/.pyenv

install:
- pip install coveralls

before_script:
- openssl version -a
- python -c 'import ssl; print(ssl.OPENSSL_VERSION)'
- python -c 'import ssl; print(ssl.HAS_NPN)'
- python -c 'import ssl; print(ssl.HAS_ALPN)'
- make depends
- python -c 'from OpenSSL import SSL; print(SSL.SSLeay_version(SSL.SSLEAY_VERSION))'
- ./.travis/install.sh

script:
- make test
- make flake8
- ./.travis/run.sh

after_success:
- coveralls
- ./.travis/after.sh

notifications:
email:
Expand Down
12 changes: 12 additions & 0 deletions .travis/after.sh
@@ -0,0 +1,12 @@
#!/bin/bash

PYENV_ROOT="$HOME/.pyenv"
PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
pyenv local $PYTHON_VERSION
pyenv global $PYTHON_VERSION

ENV=$HOME/env
source $ENV/bin/activate

coveralls
30 changes: 30 additions & 0 deletions .travis/install.sh
@@ -0,0 +1,30 @@
#!/bin/bash

set -ex

PYENV_ROOT="$HOME/.pyenv"
git clone https://github.com/yyuu/pyenv.git $PYENV_ROOT
PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
pyenv install $PYTHON_VERSION -s
pyenv local $PYTHON_VERSION
pyenv global $PYTHON_VERSION
pyenv rehash
which python
python --version
pip install --upgrade pip virtualenv

ENV=$HOME/env
virtualenv $ENV
source $ENV/bin/activate
echo $VIRTUAL_ENV
python --version

pip install coveralls

openssl version -a
python -c 'import ssl; print(ssl.OPENSSL_VERSION)'
python -c 'import ssl; print(ssl.HAS_NPN)'
python -c 'import ssl; print(ssl.HAS_ALPN)'
make depends
python -c 'from OpenSSL import SSL; print(SSL.SSLeay_version(SSL.SSLEAY_VERSION))'
11 changes: 11 additions & 0 deletions .travis/run.sh
@@ -0,0 +1,11 @@
#!/bin/bash

PYENV_ROOT="$HOME/.pyenv"
PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"

ENV=$HOME/env
source $ENV/bin/activate

make test
make flake8
6 changes: 3 additions & 3 deletions apns/ssl_context/stdlib.py
Expand Up @@ -9,9 +9,9 @@

from hyper.tls import H2_NPN_PROTOCOLS

assert ssl.OPENSSL_VERSION_INFO[:3] >= (1, 0, 1), 'TLSv1.2 is required and ' \
'is not supported by the version of OpenSSL that Python was compiled ' \
'against'
assert hasattr(ssl, 'HAS_ALPN'), 'Your version of Python does not support ' \
'ALPN, or was compiled against a version of OpenSSL that does not ' \
'support it.'

assert hasattr(ssl, 'PROTOCOL_TLSv1_2'), 'TLSv1.2 is required and is not ' \
'supported by your version of Python'
Expand Down
21 changes: 13 additions & 8 deletions tests/test_stdlib_ssl_context.py
Expand Up @@ -4,7 +4,7 @@
import ssl

import pytest
from mock import patch, Mock
from mock import patch

from apns import make_ssl_context

Expand All @@ -15,17 +15,22 @@ def test_require_tls1_2(self):
make_ssl_context('cert.pem', 'key.pem',
protocol=ssl.PROTOCOL_TLSv1_1)

@patch('apns.ssl_context.stdlib.ssl')
def test_make_context_sets_apln_npn_protocols(self, mock_ssl):
mock_ssl.PROTOCOL_TLSv1_2 = 1
ctx_mock = Mock()
mock_ssl.SSLContext.return_value = ctx_mock
ctx = make_ssl_context('cert.pem', 'key.pem')
@patch('apns.ssl_context.stdlib.ssl.SSLContext')
def test_make_context_sets_apln_npn_protocols(self, mock_ctx):
ctx = make_ssl_context('cert.pem', 'key.pem', password='test')

args, _ = mock_ctx.call_args
assert ssl.PROTOCOL_TLSv1_2 == args[0]

args, kwargs = ctx.load_cert_chain.call_args
assert 'cert.pem' == args[0]
assert 'key.pem' == kwargs['keyfile']
assert 'test' == kwargs['password']

assert ctx is ctx_mock
args, _ = ctx.set_alpn_protocols.call_args
alpn_protos = args[0]
assert 'h2' in alpn_protos

args, _ = ctx.set_npn_protocols.call_args
npn_protos = args[0]
assert 'h2' in npn_protos

0 comments on commit 2ef390f

Please sign in to comment.