Skip to content

Commit 57ae317

Browse files
committed
Some testing logic.
1 parent a751465 commit 57ae317

File tree

3 files changed

+95
-0
lines changed

3 files changed

+95
-0
lines changed

test/test_osx.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Tests of the OS X-specific functionality in certitude. These tests will only
4+
run on the OS X platform, and will otherwise be skipped.
5+
"""
6+
import os.path
7+
import platform
8+
9+
import pytest
10+
11+
import certitude
12+
import certitude.osx
13+
14+
15+
is_osx = (platform.system() == 'Darwin')
16+
17+
18+
@pytest.mark.skipif(not is_osx, reason="OS X tests skipped on this platform")
19+
class TestOSX(object):
20+
def test_os_x_certificate_string_contains_pem_files(self):
21+
"""
22+
Calling the OS X-specific certificate_string function gives PEM files.
23+
"""
24+
data = certitude.osx.certificate_string()
25+
data.rstrip()
26+
assert data.startswith(b'-----BEGIN CERTIFICATE-----')
27+
assert data.endswith(b'-----END CERTIFICATE-----')
28+
29+
def test_certificate_string_matches_osx_cert_string(self):
30+
"""
31+
The OS X-specific certificate_string function gives the same output as
32+
the "general" one.
33+
"""
34+
specific = certitude.osx.certificate_string()
35+
general = certitude.certificate_string()
36+
37+
assert specific == general
38+
39+
def test_certificate_file_contains_certificate_string(self):
40+
"""
41+
Confirm the certificate file written out is the same as the certificate
42+
string generated.
43+
"""
44+
with certitude.CertificateFile() as f:
45+
file_data = f.read()
46+
47+
certstring = certitude.certificate_string()
48+
assert certstring == file_data
49+
50+
def test_certificate_file_is_deleted_after_context_manager(self):
51+
"""
52+
The certificate file gets deleted after the context manager is exited.
53+
"""
54+
with certitude.CertificateFile() as f:
55+
path = f.path
56+
assert os.path.exists(path)
57+
58+
assert not os.path.exists(path)
59+
60+
def test_certificate_file_is_deleted_after_destroy(self):
61+
"""
62+
The certificate file gets deleted after the destroy method is called.
63+
"""
64+
f = certitude.CertificateFile()
65+
f.build()
66+
path = f.path
67+
assert os.path.exists(path)
68+
69+
f.destroy()
70+
assert not os.path.exists(path)
71+
72+
def test_cannot_read_destroyed_tempfile(self):
73+
"""
74+
Destroying a tempfile prevents reading from it.
75+
"""
76+
with certitude.CertificateFile() as f:
77+
assert len(f.read(1)) == 1
78+
79+
with pytest.raises(AttributeError):
80+
f.read()

test_requirements.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
pytest==2.8.5
2+
pytest-cov==2.2.0
3+
pytest-xdist==1.13.1
4+
hypothesis==1.16.0

tox.ini

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[tox]
2+
envlist = py27, py33, py34, py35, pypy, lint
3+
4+
[testenv]
5+
deps= -r{toxinidir}/test_requirements.txt
6+
commands= py.test {toxinidir}/test/
7+
8+
[testenv:lint]
9+
basepython=python3.4
10+
deps = flake8==2.5.1
11+
commands = flake8 --max-complexity 10 src/certitude test

0 commit comments

Comments
 (0)