Ejemplo n.º 1
0
    def write_diff(self, label, expected=False, verbose=False):
        config = ForkConfig()
        config.read_from_branch("master", self.git_dir)
        exclude_files = config.appropriated_files + config.removed_files

        if verbose:
            print(f"Writing diff '{label}' ...")

        if expected:
            suffix = "expected"
        else:
            suffix = "actual"
        clonemachine_filename = f"clonemachine-{label}-{suffix}.diff"
        diff_file = self.test_data_path / clonemachine_filename

        exclude_options = [
            f":(exclude){filename}" for filename in exclude_files
        ]
        diff = self.run_git(["diff", self.bitcoin_git_revision] +
                            exclude_options)

        with diff_file.open("w") as file:
            file.write(diff)
            file.write("\n")

        clonemachine_git_revision = self.get_git_revision(cwd=".")
        if self.run_git(["diff-index", "HEAD"], "."):
            clonemachine_git_revision += "+changes"

        unite_git_revision_master = self.get_git_revision("master")

        meta_data = {
            "bitcoin_branch":
            self.bitcoin_branch,
            "bitcoin_commit_date":
            self.get_commit_date(self.bitcoin_git_revision),
            "bitcoin_git_revision":
            self.bitcoin_git_revision,
            "clonemachine_commit_date":
            self.get_commit_date(clonemachine_git_revision, "."),
            "clonemachine_git_revision":
            clonemachine_git_revision,
            "unit_e_commit_date":
            self.get_commit_date(unite_git_revision_master),
            "unit_e_git_revision":
            unite_git_revision_master,
        }
        meta_output = ""
        for item in meta_data:
            meta_output += item + ": " + meta_data[item] + "\n"
        meta_filename = clonemachine_filename + ".meta"
        with (self.test_data_path / meta_filename).open("w") as file:
            file.write(meta_output)
        if verbose:
            print(meta_output)
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
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
Ejemplo n.º 4
0
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
Ejemplo n.º 5
0
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
Ejemplo n.º 6
0
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
Ejemplo n.º 7
0
  --unit-e-branch=<name>      Name of unit-e branch [default: master]
  --bitcoin-branch=<name>     Name of bitcoin branch (e.g. bitcoin/master), when
                              this option is set, the diff of appropriated files
                              is shown
"""
from docopt import docopt
import sys

from processor import Processor
from fork import Fork
from fork import ForkConfig
from unit_e_substituter import UnitESubstituter

if __name__ == "__main__":
    arguments = docopt(__doc__)
    processor = Processor(ForkConfig())
    unit_e_branch = arguments["--unit-e-branch"]
    bitcoin_branch = arguments["--bitcoin-branch"]
    if arguments["fork"]:
        Fork(unit_e_branch, bitcoin_branch).run()
    elif arguments["file"]:
        filename = arguments["<filename>"]
        print(f"Substituting strings in file {filename}")
        processor.substitute_bitcoin_core_identifier_in_file(filename)
        processor.substitute_bitcoin_identifier_in_file(filename)
        processor.replace_in_file(filename,
                                  "BTC",
                                  "UTE",
                                  match_before="$|[^a-bd-ln-tv-zA-Z]")
    elif arguments["substitute-unit-e-naming"]:
        UnitESubstituter().substitute_naming(processor)