Completed
Push — develop ( e4f288...dec8f0 )
by Jace
02:13
created

yorm.test.exists()   A

Complexity

Conditions 1

Size

Total Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 1
dl 0
loc 2
rs 10
1
"""Unit tests for the `yorm` package."""
2
3
import os
4
import time
5
import logging
6
7
import expecter
8
9
10
def is_true(x):
11
    return x is True
12
13
14
def is_false(x):
15
    return x is False
16
17
18
def exists(x):
19
    return os.path.exists(x)
20
21
22
def missing(x):
23
    return not os.path.exists(x)
24
25
26
expecter.add_expectation(is_true)
27
expecter.add_expectation(is_false)
28
expecter.add_expectation(exists)
29
expecter.add_expectation(missing)
30
31
32
def strip(text, tabs=None, end='\n'):
33
    """Strip leading whitespace indentation on multiline string literals."""
34
    lines = []
35
36
    for line in text.strip().splitlines():
37
        if not tabs:
38
            tabs = line.count(' ' * 4)
39
        lines.append(line.replace(' ' * tabs * 4, '', 1))
40
41
    return '\n'.join(lines) + end
42
43
44
def refresh_file_modification_times(seconds=1.1):
45
    """Sleep to allow file modification times to refresh."""
46
    logging.info("Delaying for %s second%s...", seconds,
47
                 "" if seconds == 1 else "s")
48
    time.sleep(seconds)
49