|
1
|
|
|
# pylint: disable=missing-docstring,unused-variable,unused-argument,expression-not-assigned,singleton-comparison |
|
2
|
|
|
import time |
|
3
|
|
|
from mock import patch, Mock |
|
4
|
|
|
|
|
5
|
|
|
import pytest |
|
6
|
|
|
from expecter import expect |
|
7
|
|
|
|
|
8
|
|
|
from coveragespace.plugins import get_coverage, cache, _launched_recently |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
class MockCoverage(Mock): |
|
12
|
|
|
|
|
13
|
|
|
@staticmethod |
|
14
|
|
|
def report(*args, **kwargs): |
|
15
|
|
|
return 42.456 |
|
16
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
def describe_get_coverage(): |
|
19
|
|
|
|
|
20
|
|
|
@pytest.fixture |
|
21
|
|
|
def coveragepy_data(tmpdir): |
|
22
|
|
|
cwd = tmpdir.chdir() |
|
23
|
|
|
with open("foobar.py", 'w') as stream: |
|
24
|
|
|
pass |
|
25
|
|
|
with open(".coverage", 'w') as stream: |
|
26
|
|
|
stream.write(""" |
|
27
|
|
|
!coverage.py: This is a private format, don\'t read it directly! |
|
28
|
|
|
{"arcs":{"foobar.py": [[-1, 3]]}} |
|
29
|
|
|
""".strip()) |
|
30
|
|
|
|
|
31
|
|
|
@patch('coverage.Coverage', MockCoverage) |
|
32
|
|
|
def it_supports_coveragepy(coveragepy_data): |
|
33
|
|
|
expect(get_coverage()) == 42.5 |
|
34
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
def describe_launched_recently(): |
|
37
|
|
|
|
|
38
|
|
|
def when_never_launched(): |
|
39
|
|
|
cache.set('mock/path', 0) |
|
40
|
|
|
expect(_launched_recently('mock/path')) == False |
|
41
|
|
|
|
|
42
|
|
|
def when_just_launched(): |
|
43
|
|
|
cache.set('mock/path', time.time()) |
|
44
|
|
|
expect(_launched_recently('mock/path')) == True |
|
45
|
|
|
|
|
46
|
|
|
def when_launched_59_minutes_ago(): |
|
47
|
|
|
cache.set('mock/path', time.time() - 60 * 59) |
|
48
|
|
|
expect(_launched_recently('mock/path')) == True |
|
49
|
|
|
|
|
50
|
|
|
def when_launched_61_minutes_ago(): |
|
51
|
|
|
cache.set('mock/path', time.time() - 60 * 61) |
|
52
|
|
|
expect(_launched_recently('mock/path')) == False |
|
53
|
|
|
|