File: test_bump_cmd.py

package info (click to toggle)
trash-cli 0.24.5.26-0.3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,972 kB
  • sloc: python: 9,789; sh: 121; makefile: 11
file content (52 lines) | stat: -rw-r--r-- 1,985 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
from tests.support.capture_exit_code import capture_exit_code
from tests.support.put.fake_fs.fake_fs import FakeFs
from tests.support.tools.bump_cmd import BumpCmd
from tests.test_dev_tools.support.fake_cal import FakeCal
from tests.test_dev_tools.support.fake_system import FakeSystem


class TestBumpCmd:
    def setup_method(self):
        self.system = FakeSystem()
        self.print_calls = []
        self.fs = FakeFs()
        self.cmd = BumpCmd(self.system.os_system, self.print_calls.append,
                           self.fs, FakeCal("2024-05-01"))

    def test_when_dirty(self):
        exit_code = capture_exit_code(lambda: self.cmd.run_bump("/", []))

        assert exit_code == 1
        assert self.print_calls == ['Dirty']
        assert self.system.os_system_calls == ['git diff-index --quiet HEAD']

    def test_when_clean(self):
        self.system.set_clean()
        self.fs.mkdir('trashcli')
        self.fs.make_file('trashcli/trash.py', "version=x.y.x")

        exit_code = capture_exit_code(lambda: self.cmd.run_bump("/", []))

        assert exit_code == None
        assert self.print_calls == []
        assert self.system.os_system_calls == [
            'git diff-index --quiet HEAD',
            'git commit -m "Bump version to \'0.24.5.1\'" -a']
        assert self.fs.read_all_files() == [
            ('/trashcli/trash.py', "version = '0.24.5.1'")]

    def test_when_clean_and_dry_run(self):
        self.system.set_clean()
        self.fs.mkdir('trashcli')
        self.fs.make_file('trashcli/trash.py', "version=x.y.x")

        exit_code = capture_exit_code(
            lambda: self.cmd.run_bump("/", ['--dry-run']))

        assert exit_code == None
        assert self.print_calls == [
            'git commit -m "Bump version to \'0.24.5.1\'" -a']
        assert self.system.os_system_calls == [
            'git diff-index --quiet HEAD']
        assert self.fs.read_all_files() == [
            ('/trashcli/trash.py', "version=x.y.x")]