-
Notifications
You must be signed in to change notification settings - Fork 5
/
test_processor.py
139 lines (109 loc) · 3.99 KB
/
test_processor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# Copyright (c) 2018-2019 The Unit-e developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or https://opensource.org/licenses/MIT.
# Unit tests for clonemachine
#
# Run them with `pytest -v test_fork.py`
import tempfile
import os
from pathlib import Path
from processor import Processor
from fork import ForkConfig
class TestSubstituteBitcoinIdentifier:
def run_and_test_substitution(self, original, expected_result):
try:
with tempfile.NamedTemporaryFile(delete=False) as file:
file.write(original.encode('utf-8'))
Processor(ForkConfig()).substitute_bitcoin_identifier_in_file(file.name)
with open(file.name) as result_file:
result = result_file.read()
assert result == expected_result
finally:
os.remove(file.name)
def test_bitcoin(self):
original = 'bitcoin bitcoin.git'
expected_result = 'unite unite.git'
self.run_and_test_substitution(original, expected_result)
def test_bitcoincore(self):
original = '''
FALLBACK_DOWNLOAD_PATH ?= https://bitcoincore.org/depends-sources
'''
self.run_and_test_substitution(original, original)
def test_ppa(self):
original = '''
sudo add-apt-repository ppa:bitcoin/bitcoin
'''
self.run_and_test_substitution(original, original)
def test_remove_trailing_whitespace(tmp_path):
original = "one \ntwo two \nno\n"
expected_result = "one\ntwo two\nno\n"
file_name = tmp_path / "test.py"
with file_name.open("w") as file:
file.write(original)
old_dir = os.getcwd()
os.chdir(tmp_path)
Processor(ForkConfig()).remove_trailing_whitespace("*.py")
os.chdir(old_dir)
with file_name.open() as result_file:
result = result_file.read()
assert result == expected_result
def test_substitute_bitcoin_identifier_in_file(tmp_path):
original = """
A Bitcoin is a BITCOIN
bitcoin
A bitcoin address
Variables: BITCOIN_CONFIG, BITCOIND_BIN, BUILD_BITCOIND
BITCOIND=${BITCOIND:-$BINDIR/bitcoind}
BITCOINCLI=${BITCOINCLI:-$BINDIR/bitcoin-cli}
BITCOINTX=${BITCOINTX:-$BINDIR/bitcoin-tx}
BITCOINQT=${BITCOINQT:-$BINDIR/qt/bitcoin-qt}
static void SetupBitcoinTxArgs()
BITCOINCONSENSUS_API_VER
"""
expected_result = """
A Unit-e is a UNIT-E
unite
A Unit-e address
Variables: UNITE_CONFIG, UNITED_BIN, BUILD_UNITED
UNITED=${UNITED:-$BINDIR/united}
UNITECLI=${UNITECLI:-$BINDIR/unite-cli}
UNITETX=${UNITETX:-$BINDIR/unite-tx}
UNITEQT=${UNITEQT:-$BINDIR/qt/unite-qt}
static void SetupUnitETxArgs()
UNITECONSENSUS_API_VER
"""
file_name = tmp_path / "test"
with file_name.open("w") as file:
file.write(original)
Processor(ForkConfig()).substitute_bitcoin_identifier_in_file(str(file_name))
with file_name.open() as result_file:
result = result_file.read()
assert result == expected_result
def test_substitute_bitcoin_identifier_in_file_copyright(tmp_path):
original = """
Bitcoin Core
# Copyright (c) 2016-2017 Bitcoin Core Developers
"""
expected_result = """
unit-e
# Copyright (c) 2016-2017 Bitcoin Core Developers
"""
file_name = tmp_path / "test"
with file_name.open("w") as file:
file.write(original)
Processor(ForkConfig()).substitute_bitcoin_core_identifier_in_file(file_name)
with file_name.open() as result_file:
result = result_file.read()
assert result == expected_result
def test_replace_in_file_regex(tmp_path):
original = " * @see https://unite.org/en/developer-reference#version"
expected_result = " * @see https://docs.unit-e.io/reference/p2p/version.html"
file_name = tmp_path / "test"
with file_name.open("w") as file:
file.write(original)
Processor(ForkConfig()).replace_in_file_regex(file_name,
r"https://unite.org/en/developer-reference#(\w+)",
r"https://docs.unit-e.io/reference/p2p/\1.html")
with file_name.open() as result_file:
result = result_file.read()
assert result == expected_result