File: test_log.py

package info (click to toggle)
yarsync 0.1.1%2Bdeb-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 624 kB
  • sloc: python: 1,905; makefile: 13
file content (96 lines) | stat: -rw-r--r-- 2,636 bytes parent folder | download
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
# -*- coding: utf-8 -*-
import os
import pytest
import sys
import time

from yarsync import YARsync
from .settings import TEST_DIR, TEST_DIR_EMPTY


def test_log_error(test_dir_read_only):
    """Test a not-yarsync directory."""
    os.chdir(test_dir_read_only)

    args = ["yarsync", "log"]
    with pytest.raises(OSError) as err:
        ys = YARsync(args)
    # the exact representation of value and the printed error message
    # are tested in test_status


def test_log_empty(mocker):
    os.chdir(TEST_DIR_EMPTY)
    mocker_print = mocker.patch("sys.stdout")

    args = ["yarsync", "log"]
    ys = YARsync(args)

    # call _log
    res = ys()
    call = mocker.call
    assert res == 0
    assert mocker_print.mock_calls == [
        call.write('No synchronization information found.'),
        call.write('\n'),
        call.write('No commits found'), call.write('\n')
    ]

def test_log(mocker):
    os.chdir(TEST_DIR)
    mocker_print = mocker.patch("sys.stdout")

    args = ["yarsync", "log"]
    ys = YARsync(args)

    # call _log
    res = ys()
    call = mocker.call
    assert res == 0

    # the date on Python 3.6 is still different (see test_commit.py)
    time1_str = time.strftime(ys.DATEFMT, time.localtime(1))
    # this time is fixed in log
    time2_str = "Thu, 01 Jan 1970 03:00:02 MSK"

    assert mocker_print.mock_calls == [
        call.write('No synchronization information found.'),
        call.write('\n'),
        call.write('commit 3 is missing'),
        call.write('\n'),
        call.write('log 3\n'),
        call.write(''),
        call.write('\n'),
        call.write('commit 2'),
        call.write('\n'),
        call.write('When: {}\nWhere: user@host\n'.format(time2_str)),
        call.write(''),
        call.write('\n'),
        call.write('commit 1'),
        call.write('\n'),
        call.write('Log is missing\nWhen: {}\n'.format(time1_str)),
        call.write(''),
    ]

    mocker_print.reset_mock()
    # yarsync log -n 1 -r
    args = ["yarsync", "log", "--max-count", "1", "--reverse"]
    ys = YARsync(args)
    res = ys()
    call = mocker.call
    assert res == 0
    assert mocker_print.mock_calls == [
        call.write('No synchronization information found.'),
        call.write('\n'),
        call.write('commit 1'),
        call.write('\n'),
        call.write('Log is missing\nWhen: {}\n'.format(time1_str)),
        call.write(''),
    ]


def test_make_commit_log_list():
    commits = [1, 3]
    logs = [2]
    ys = YARsync(["yarsync", "log"])  # the function is not called
    assert ys._make_commit_list(commits, logs) == [(1, None), (None, 2), (3, None)]