Пример #1
0
def test_two_split_panes(capsys):
    """
    Test two windows, both with split panes
    """
    builder = TmuxBuilder("session", "/var")
    builder.add_window("win1", "pane1", "window")
    builder.add_pane("pane2", SPLIT_HORIZONTAL)
    builder.run_command("top")
    builder.run_command("echo", "win1", "pane1")
    builder.add_window("win2", "pane3", "window2", "/home")
    builder.add_pane("pane4", SPLIT_VERTICAL, working_directory="/etc")
    builder.run_command("tail")
    actual = convert_lines_to_object(builder.build().split("\n"))

    expected = convert_lines_to_object(
        [
            'pushd "/var"',
            "tmux new-session -d -s session \\; \\",
            "rename-window window \\; \\",
            'send-keys "echo" "C-m" \\; \\',
            'split-window -h -c "/var" \\; \\',
            'send-keys "top" "C-m" \\; \\',
            'new-window -n window2 -c "/home" \\; \\',
            'split-window -v -c "/etc" \\; \\',
            'send-keys "tail" "C-m"',
            "popd",
        ]
    )

    assert_objects_equal(expected, actual, expected.keys(), capsys)
Пример #2
0
def test_single_pane_session(capsys):
    """
    Test creating a session with a single pane
    """

    window_data = [
        {
            "identity": "window",
            "number": 0,
            "title": "window",
            "postfix": "~-*",
            "layout": "c6e0,200x60,0,0,0",
            "panes": [{"identity": "pane", "number": 0, "command": "top"}],
        }
    ]

    window_list = set_session_parameters(
        DEFAULT_SESSION, DEFAULT_DIRECTORY, window_data,
    )

    scripter = TmuxScripter(DEFAULT_SESSION, DEFAULT_DIRECTORY)
    scripter.analyze(window_list)

    expected = convert_lines_to_object(
        GENERIC_START + ['send-keys "top" "C-m"', "popd",]
    )
    actual = convert_lines_to_object(scripter.commands.split("\n"))

    assert_objects_equal(expected, actual, expected.keys(), capsys)
Пример #3
0
def test_differences(capsys):
    """
    Test differences between panes
    """
    pane1 = Pane("identity1", "fake_window", SPLIT_VERTICAL)
    pane2 = Pane("identity2", "fake_window", SPLIT_VERTICAL)

    expected = {"none": {}}
    actual = {"none": pane1.get_difference(pane2)}

    pane2 = Pane("identity3", "fake_window", SPLIT_HORIZONTAL)
    expected["dir"] = {
        "direction": {
            "expected": SPLIT_VERTICAL,
            "actual": SPLIT_HORIZONTAL
        }
    }
    actual["dir"] = pane1.get_difference(pane2)

    pane2 = Pane("identity4", "fake_window", SPLIT_VERTICAL)
    pane1.set_size(10, 20)
    pane2.set_size(30, 40)
    expected["size"] = {
        "width": {
            "expected": 10,
            "actual": 30
        },
        "height": {
            "expected": 20,
            "actual": 40
        },
    }
    actual["size"] = pane1.get_difference(pane2)

    assert_objects_equal(expected, actual, expected.keys(), capsys)
Пример #4
0
def test_double_three_split_with_target(capsys):
    """
    Test three-way split in two directions, with window targets
    0 |
    - | 2
    1 |

    0 | 1
    -----
      2
    """
    builder = TmuxBuilder("session", "/")
    builder.add_window("w1", "w1p1", "w1")
    builder.add_pane("w1p2", SPLIT_HORIZONTAL)
    builder.add_window("w2", "w2p1", "w2", "/home")
    builder.add_pane("w2p2", SPLIT_VERTICAL, "w2", working_directory="/etc")
    builder.add_pane("w1p3", SPLIT_VERTICAL, split_from="w1p1")
    builder.add_pane("w2p3", SPLIT_HORIZONTAL, split_from="w2p1")
    actual = convert_lines_to_object(builder.build().split("\n"))

    expected = convert_lines_to_object(
        [
            'pushd "/"',
            "tmux new-session -d -s session \\; \\",
            "rename-window w1 \\; \\",
            'split-window -h -c "/" \\; \\',
            'split-window -v -t session:0.0 -c "/" \\; \\',
            'new-window -n w2 -c "/home" \\; \\',
            'split-window -v -c "/etc" \\; \\',
            'split-window -h -t session:1.0 -c "/home"',
            "popd",
        ]
    )

    assert_objects_equal(expected, actual, expected.keys(), capsys)
Пример #5
0
def test_multiple_sequential_splits(capsys):
    """
    Test splitting a window in multiple directions, sequentially
    """
    builder = TmuxBuilder("session", "/var")
    builder.add_window("w1", "w1p1", "w1")
    builder.add_pane("w1p2", SPLIT_HORIZONTAL)
    builder.add_pane("w1p3", SPLIT_VERTICAL)
    builder.add_pane("w1p4", SPLIT_VERTICAL)
    builder.add_pane("w1p5", SPLIT_HORIZONTAL)
    actual = convert_lines_to_object(builder.build().split("\n"))

    expected = convert_lines_to_object(
        [
            'pushd "/var"',
            "tmux new-session -d -s session \\; \\",
            "rename-window w1 \\; \\",
            'split-window -h -c "/var" \\; \\',
            'split-window -v -c "/var" \\; \\',
            'split-window -v -c "/var" \\; \\',
            'split-window -h -c "/var"',
            "popd",
        ]
    )

    assert_objects_equal(expected, actual, expected.keys(), capsys)
Пример #6
0
def test_middle_split_pane_with_sizing(capsys):
    """
    Split a pane in between two others, setting its size
    """
    builder = TmuxBuilder("session", "/var").set_terminal_size(200, 200)
    builder.add_window("w0", "w0p0", "w0")
    builder.set_pane_width(40)
    builder.add_pane("w0p1", SPLIT_HORIZONTAL)
    builder.add_pane("w0p2", SPLIT_HORIZONTAL)
    # This becomes pane number 2, since horizontally before pane w0p3
    builder.add_pane("w0p3", SPLIT_VERTICAL, split_from="w0p1")
    builder.set_pane_width(30)
    builder.set_pane_height(20)
    actual = convert_lines_to_object(builder.build().split("\n"))

    expected = convert_lines_to_object(
        [
            'pushd "/var"',
            "tmux new-session -d -s session \\; \\",
            "rename-window w0 \\; \\",
            'split-window -h -c "/var" \\; \\',
            'split-window -h -c "/var" \\; \\',
            'split-window -v -t session:0.1 -c "/var" \\; \\',
            "resize-pane -t session:0.0 -x 80  \\; \\",
            "resize-pane -t session:0.2 -x 60 -y 40",
            "popd",
        ]
    )

    assert_objects_equal(expected, actual, expected.keys(), capsys)
Пример #7
0
def test_size_command(capsys):
    """
    Check the size command works appropriately
    """
    window = type("FakeWindow", (object, ), {"number": 1})
    target = get_pane_syntax("s", 1, 1)
    pane = Pane("identity1", window,
                SPLIT_VERTICAL).set_session_name("s").set_number(1)
    expected = {"none": ""}
    actual = {"none": pane.get_size_command()}

    pane.set_size(10)
    expected["width"] = "resize-pane -t {0} -x {1} ".format(target, 10)
    actual["width"] = pane.get_size_command()

    pane.set_size(10, 20)
    expected["both"] = "resize-pane -t {0} -x {1} -y {2}".format(
        target, 10, 20)
    actual["both"] = pane.get_size_command()

    pane = (Pane("identity2", window,
                 SPLIT_VERTICAL).set_session_name("s").set_number(1).set_size(
                     0, 20))
    expected["both"] = "resize-pane -t {0}  -y {1}".format(target, 20)
    actual["both"] = pane.get_size_command()

    assert_objects_equal(expected, actual, expected.keys(), capsys)
Пример #8
0
def test_get_differences(capsys):
    """
    Test getting window differences
    """
    window = Window("win", "name", True)
    window2 = Window("win2", "name2", False)
    expected = {
        "initial": {
            "name": {"expected": "name", "actual": "name2"},
            "first": {"expected": True, "actual": False},
        }
    }
    actual = {"initial": window.get_difference(window2)}

    window.set_session_name("s")
    window2.set_session_name("s2")
    window.set_start_dir('-c "/home"')
    window2.set_start_dir('-c "/"')

    expected["props"] = deepcopy(expected["initial"])
    expected["props"].update(
        {
            "session_name": {"expected": "s", "actual": "s2"},
            "start_dir": {"expected": '-c "/home"', "actual": '-c "/"'},
        }
    )

    actual["props"] = window.get_difference(window2)

    assert_objects_equal(expected, actual, expected.keys(), capsys)
Пример #9
0
def test_pane_differences(capsys):
    """
    Test getting differences between panes
    """
    panes1 = [Pane("pane1", "p", SPLIT_HORIZONTAL).set_number(0)]
    panes2 = [Pane("pane2", "p2", SPLIT_VERTICAL).set_number(1)]

    window1 = Window("win1", "window")
    window1.panes = panes1
    window2 = Window("win2", "window2")
    window2.panes = panes2

    expected = {
        "single": [
            {
                "direction": {"expected": SPLIT_HORIZONTAL, "actual": SPLIT_VERTICAL,},
                "split_from": {},
                "start_dir": {},
            }
        ]
    }
    actual = {"single": window1.get_pane_differences(window2.panes)}

    panes1.append(Pane("pane3", "p", SPLIT_HORIZONTAL))
    panes2.append(Pane("pane4", "p", SPLIT_HORIZONTAL))
    panes1[-1].set_target("pane1")
    panes2[-1].set_target("pane2")

    expected["multi"] = deepcopy(expected["single"])
    expected["multi"].append(
        {"split_from": {"expected": "pane1", "actual": "pane2"}, "start_dir": {}}
    )
    actual["multi"] = window1.get_pane_differences(window2.panes)

    assert_objects_equal(expected, actual, expected.keys(), capsys)
Пример #10
0
def test_get_split_command(capsys):
    """
    Tests the command to generate the split works correctly
    """
    pane = Pane("identity", type("Window", (object, ), {"number": 1}),
                SPLIT_VERTICAL)

    expected = {}
    actual = {}

    window = type("FakeWindow", (object, ), {"number": 1})
    (Pane("pane1", window,
          SPLIT_HORIZONTAL).set_session_name("session").set_number(1))

    expected["empty"] = "split-window -{0}".format(SPLIT_VERTICAL)
    actual["empty"] = pane.get_split_command()

    pane.set_start_dir('-c "home"')
    expected["with_dir"] = "split-window -{0} {1}".format(
        SPLIT_VERTICAL, '-c "home"')
    actual["with_dir"] = pane.get_split_command()

    pane.set_session_name("session").set_number(0).set_target("pane1")
    expected["all"] = "split-window -{0} -t {2} {1}".format(
        SPLIT_VERTICAL, '-c "home"', get_pane_syntax("session", 1, 1))
    actual["all"] = pane.get_split_command()

    assert_objects_equal(expected, actual, expected.keys(), capsys)
Пример #11
0
def test_creation_get_set(capsys):
    """
    Test basic creation of a window
    """
    properties = {"identity": "window", "name": "thing", "first": True, "panes": []}
    window = Window(properties["identity"], properties["name"], properties["first"])

    expected = {"create": deepcopy(properties)}
    actual = {"create": window}

    properties.update({"number": 5})
    window.set_number(properties["number"])
    expected["number"] = deepcopy(properties)
    actual["number"] = window

    properties.update({"session_name": "session"})
    window.set_session_name(properties["session_name"])
    expected["session"] = deepcopy(properties)
    actual["session"] = window

    properties.update({"start_dir": '-c "/var/www"'})
    window.set_start_dir(properties["start_dir"])
    expected["dir"] = deepcopy(properties)
    actual["dir"] = window

    expected["pcount"] = 0
    actual["pcount"] = window.get_pane_count()

    expected["first"] = properties["first"]
    actual["first"] = window.is_first()

    assert_objects_equal(expected, actual, expected.keys(), capsys)
Пример #12
0
def test_command_quoting(capsys):
    """
    Verify commands are escaped properly
    """
    pane = Pane("identity", "fake_window", SPLIT_VERTICAL)
    pane.set_command("foo")

    expected = {}
    actual = {}
    expected["command1"] = '"foo" "C-m"'
    actual["command1"] = pane.command

    pane.set_command("foo", False)
    expected["command2"] = '"foo"'
    actual["command2"] = pane.command

    pane.set_command('echo "foo"')
    expected["command3"] = '"echo \\"foo\\"" "C-m"'
    actual["command3"] = pane.command

    pane.set_command("echo 'foo'")
    expected["command4"] = '"echo \'foo\'" "C-m"'
    actual["command4"] = pane.command

    pane.set_command('"echo \\"things\\"" "C-m"')
    expected["already_quoted"] = '"echo \\"things\\"" "C-m"'
    actual["already_quoted"] = pane.command

    assert_objects_equal(expected, actual, expected.keys(), capsys)
Пример #13
0
def test_get_sets(capsys):
    """
    Test setting and getting of attributes
    """
    (Pane("target", "fake_window",
          None).set_session_name("session").set_number(0))
    pane = Pane("identity", "fake_window", SPLIT_VERTICAL, True)
    pane.set_number(5).set_session_name("session").set_target(
        "target").set_start_dir("dir").set_size(30, 40)

    properties = {
        "identity": "identity",
        "number": 5,
        "window": "fake_window",
        "direction": SPLIT_VERTICAL,
        "split_from": "target",
        "session_name": "session",
        "start_dir": "dir",
        "command": "",
        "width": 30,
        "height": 40,
        "is_first": True,
    }

    assert_objects_equal(properties, pane, properties.keys(), capsys)
Пример #14
0
def test_nested_middle_split(capsys):
    """
    Tests a layout which has nested splits, but around a middle section

      0  |   |  3
     --- | 2 | ---
      1  |   |  4
    """

    window_layout = (
        "32ff,200x60,0,0{"
        "30x60,0,0[30x20,0,0,49,30x40,0,31,53],"
        "100x60,31,0,50,"
        "70x60,131,0[70x45,131,0,51,70x15,131,46,52]}"
    )
    window_data = [
        {
            "identity": "window",
            "number": 0,
            "title": "window",
            "postfix": "~-",
            "layout": window_layout,
            "panes": [
                {"identity": "pane0", "number": 0},
                {"identity": "pane1", "number": 1, "parent": "pane0"},
                {"identity": "pane2", "number": 2, "parent": "pane0"},
                {"identity": "pane3", "number": 3, "parent": "pane2"},
                {"identity": "pane4", "number": 4, "parent": "pane3"},
            ],
        }
    ]

    window_list = set_session_parameters(
        DEFAULT_SESSION, DEFAULT_DIRECTORY, window_data,
    )

    scripter = TmuxScripter(DEFAULT_SESSION, DEFAULT_DIRECTORY).set_terminal_size(
        TERMINAL_WIDTH, TERMINAL_HEIGHT
    )
    scripter.analyze(window_list)

    expected = convert_lines_to_object(
        GENERIC_START
        + [
            'split-window -h -t session:0.0 -c "/home/brett" \\; \\',
            'split-window -h -t session:0.1 -c "/home/brett" \\; \\',
            'split-window -v -t session:0.0 -c "/home/brett" \\; \\',
            'split-window -v -t session:0.3 -c "/home/brett" \\; \\',
            "resize-pane -t session:0.0 -x 30 -y 20 \\; \\",
            "resize-pane -t session:0.2 -x 100 -y 60 \\; \\",
            "resize-pane -t session:0.3 -x 70 -y 45 \\; \\",
            "resize-pane -t session:0.1 -x 30 -y 40 \\; \\",
            "resize-pane -t session:0.4 -x 70 -y 15",
            "popd",
        ]
    )
    actual = convert_lines_to_object(scripter.commands.split("\n"))

    assert_objects_equal(expected, actual, expected.keys(), capsys)
Пример #15
0
def test_get_command(capsys):
    """
    Test the window creation command
    """
    window = Window("win1", "name", True)
    expected = {"first": "rename-window name"}
    actual = {"first": window.get_create_command()}

    window2 = Window("win2", "second").set_start_dir('-c "/home"')
    expected["second"] = 'new-window -n second -c "/home"'
    actual["second"] = window2.get_create_command()

    assert_objects_equal(expected, actual, expected.keys(), capsys)
Пример #16
0
def test_get_command(capsys):
    """
    Verify getting the command works
    """
    pane = Pane("identity", "fake_window", SPLIT_VERTICAL)

    expected = {"none": ""}
    actual = {"none": pane.get_run_command()}

    pane.set_command("foo")
    expected["cmd"] = 'send-keys "foo" "C-m"'
    actual["cmd"] = pane.get_run_command()

    assert_objects_equal(expected, actual, expected.keys(), capsys)
Пример #17
0
def test_split_pane_session(capsys):
    """
    Test a session with a single window, with a split pane
    """

    window_data = [
        {
            "identity": "window",
            "number": 0,
            "title": "window",
            "postfix": "~-",
            "dir": DEFAULT_DIRECTORY,
            "layout": "c6e0,200x60,0,0{100x60,0,0,0,100x60,101,0,1}",
            "panes": [
                {"identity": "pane", "number": 0, "command": "top"},
                {
                    "identity": "pane2",
                    "number": 1,
                    "dir": "/var/log",
                    "command": "tail -f syslog",
                    "parent": "pane",
                },
            ],
        }
    ]

    window_list = set_session_parameters(
        DEFAULT_SESSION, DEFAULT_DIRECTORY, window_data,
    )

    scripter = TmuxScripter(DEFAULT_SESSION, DEFAULT_DIRECTORY).set_terminal_size(
        TERMINAL_WIDTH, TERMINAL_HEIGHT
    )
    scripter.analyze(window_list)

    expected = convert_lines_to_object(
        GENERIC_START
        + [
            'send-keys "top" "C-m" \\; \\',
            'split-window -h -t session:0.0 -c "/var/log" \\; \\',
            'send-keys "tail -f syslog" "C-m" \\; \\',
            "resize-pane -t session:0.0 -x 100 -y 60 \\; \\",
            "resize-pane -t session:0.1 -x 100 -y 60",
            "popd",
        ]
    )
    actual = convert_lines_to_object(scripter.commands.split("\n"))

    assert_objects_equal(expected, actual, expected.keys(), capsys)
Пример #18
0
def test_pane_creation(capsys):
    """
    Test that a pane that is created has the proper attributes
    """
    pane = Pane("identity", "fake_window", SPLIT_HORIZONTAL)
    properties = {
        "identity": "identity",
        "window": "fake_window",
        "direction": SPLIT_HORIZONTAL,
        "split_from": None,
        "command": "",
        "width": 0,
        "height": 0,
        "is_first": False,
    }

    assert_objects_equal(properties, pane, properties.keys(), capsys)
Пример #19
0
def test_add_pane(capsys):
    """
    Test adding a pane
    """
    window = Window("id", "name").set_number(1)
    expected = {"init": []}
    actual = {"init": deepcopy(window.panes)}

    pane = (
        Pane("identity", window, SPLIT_HORIZONTAL)
        .set_session_name("session")
        .set_number(0)
    )
    window.add_pane(pane)

    expected["single"] = 1
    actual["single"] = window.get_pane_count()

    pane2 = (
        Pane("identity2", window, SPLIT_HORIZONTAL)
        .set_session_name("session")
        .set_number(2)
        .set_target("identity")
    )
    window.add_pane(pane2)
    expected["get"] = {"id": id(pane), "num": 1}
    actual["get"] = {"id": id(window.get_pane(0)), "num": pane2.number}

    pane3 = (
        Pane("identity3", window, SPLIT_HORIZONTAL)
        .set_session_name("session")
        .set_number(2)
        .set_target("identity")
    )
    window.add_pane(pane3)
    expected["inserted"] = 1
    actual["inserted"] = pane3.number
    expected["previous"] = 2
    actual["previous"] = pane2.number

    expected["middle"] = id(pane2)
    actual["middle"] = id(window.get_pane(1))

    assert_objects_equal(expected, actual, expected.keys(), capsys)
Пример #20
0
def test_single_pane_window(capsys):
    """
    Test the creation of a basic single-pane window
    """
    builder = TmuxBuilder("session", "/etc")
    builder.add_window("win1", "pane1", "window", "/home")
    builder.run_command("top")
    actual = convert_lines_to_object(builder.build().split("\n"))

    expected = convert_lines_to_object(
        [
            'pushd "/etc"',
            "tmux new-session -d -s session \\; \\",
            "rename-window window \\; \\",
            'send-keys "top" "C-m"',
            "popd",
        ]
    )

    assert_objects_equal(expected, actual, expected.keys(), capsys)
Пример #21
0
def test_create_get_set(capsys):
    """
    Test variable properties for creation, getters, and setters
    """

    builder = TmuxBuilder("session")

    expected = {"initial": {"session_name": "session", "start_dir": "", "detach": True}}
    actual = {"initial": builder}

    builder.set_terminal_size(20, 40)
    expected["size"] = {"terminal_width": 20, "terminal_height": 40}
    actual["size"] = builder

    builder = TmuxBuilder("session", "/home", False)
    expected["cwd"] = {
        "session_name": "session",
        "start_dir": "/home",
        "detach": False,
    }
    actual["cwd"] = builder

    assert_objects_equal(expected, actual, expected.keys(), capsys)
Пример #22
0
def test_get_target(capsys):
    """
    Verify getting of target works as expected
    """
    window = type("FakeWindow", (object, ), {"number": 1})
    pane = (Pane("identity1", window,
                 SPLIT_VERTICAL).set_session_name("session").set_number(1))

    pane2 = (Pane("identity2", window,
                  SPLIT_VERTICAL).set_session_name("session").set_number(2))

    expected = {"none": None}
    actual = {"none": pane.get_target()}

    pane.set_target("identity2")
    expected["target"] = get_pane_syntax("session", 1, 2)
    actual["target"] = pane.get_target()

    pane2.set_number(3)

    expected[""] = get_pane_syntax("session", 1, 3)
    actual[""] = pane2.get_target(True)

    assert_objects_equal(expected, actual, expected.keys(), capsys)
Пример #23
0
def test_two_window_single_pane(capsys):
    """
    Test two windows with single panes
    """
    builder = TmuxBuilder("session", "/var")
    builder.add_window("win1", "pane1", "window")
    builder.run_command("top")
    builder.add_window("win2", "pane2", "window2", "/home")
    builder.run_command("tail")
    actual = convert_lines_to_object(builder.build().split("\n"))

    expected = convert_lines_to_object(
        [
            'pushd "/var"',
            "tmux new-session -d -s session \\; \\",
            "rename-window window \\; \\",
            'send-keys "top" "C-m" \\; \\',
            'new-window -n window2 -c "/home" \\; \\',
            'send-keys "tail" "C-m"',
            "popd",
        ]
    )

    assert_objects_equal(expected, actual, expected.keys(), capsys)
Пример #24
0
def test_two_perpendicular_windows(capsys):
    """
    Check a session with two windows, one split vertically, the horizontally
    Should make this:

    Window 0:
       |  1
     0 | ---
       |  2

    Window 1:
      0
    -----
    1 | 2

    """

    window_layout_one = (
        "b652,200x60,0,0{100x60,0,0,255,100x60,101,0"
        "[100x40,101,0,256,100x20,101,41,257]}"
    )
    window_layout_two = (
        "6fc3,200x60,0,0[200x30,0,0,258,"
        "200x30,0,31{150x30,0,31,259,50x30,151,31,260}]"
    )
    window_data = [
        {
            "identity": "window",
            "number": 0,
            "title": "window",
            "postfix": "~-",
            "layout": window_layout_one,
            "panes": [
                {"identity": "pane", "number": 0, "command": "top"},
                {
                    "identity": "pane2",
                    "number": 1,
                    "dir": "/var/log",
                    "command": "tail -f syslog",
                    "parent": "pane",
                },
                {
                    "identity": "pane3",
                    "number": 2,
                    "command": "vi test.py",
                    "parent": "pane2",
                },
            ],
        },
        {
            "identity": "window2",
            "number": 1,
            "title": "zsh",
            "postfix": "*Z",
            "dir": "/root",
            "layout": window_layout_two,
            "panes": [
                {
                    "identity": "pane4",
                    "number": 0,
                    # This should override the window directory
                    "dir": "/home/brett",
                },
                {
                    "identity": "pane5",
                    "number": 1,
                    "command": "cat bar",
                    "parent": "pane4",
                },
                {
                    "identity": "pane6",
                    "number": 2,
                    "dir": DEFAULT_DIRECTORY,
                    "command": "netstat -noap | grep 443",
                    "parent": "pane5",
                },
            ],
        },
    ]

    window_list = set_session_parameters(
        DEFAULT_SESSION, DEFAULT_DIRECTORY, window_data,
    )

    scripter = TmuxScripter(DEFAULT_SESSION, DEFAULT_DIRECTORY).set_terminal_size(
        TERMINAL_WIDTH, TERMINAL_HEIGHT
    )
    scripter.analyze(window_list)

    expected = convert_lines_to_object(
        GENERIC_START
        + [
            'send-keys "top" "C-m" \\; \\',
            'split-window -h -t session:0.0 -c "/var/log" \\; \\',
            'send-keys "tail -f syslog" "C-m" \\; \\',
            'split-window -v -t session:0.1 -c "/home/brett" \\; \\',
            'send-keys "vi test.py" "C-m" \\; \\',
            'new-window -n zsh -c "/home/brett" \\; \\',
            'split-window -v -t session:1.0 -c "/root" \\; \\',
            'send-keys "cat bar" "C-m" \\; \\',
            'split-window -h -t session:1.1 -c "/home/brett" \\; \\',
            'send-keys "netstat -noap | grep 443" "C-m" \\; \\',
            "resize-pane -t session:0.0 -x 100 -y 60 \\; \\",
            "resize-pane -t session:0.1 -x 100 -y 40 \\; \\",
            "resize-pane -t session:0.2 -x 100 -y 20 \\; \\",
            "resize-pane -t session:1.0 -x 200 -y 30 \\; \\",
            "resize-pane -t session:1.1 -x 150 -y 30 \\; \\",
            "resize-pane -t session:1.2 -x 50 -y 30",
            "popd",
        ]
    )
    actual = convert_lines_to_object(scripter.commands.split("\n"))

    assert_objects_equal(expected, actual, expected.keys(), capsys)
Пример #25
0
def test_horizontal_tri_split(capsys):
    """
    A complex horizontal layout with eight panes

     0 |     |  5
    ---|  3  | ---
     1 | --- |  6
    ---|  4  | ---
     2 |     |  7
    """

    window_layout = (
        "32ff,200x60,0,0"
        "{30x60,0,0[30x10,0,0,49,30x30,0,11,53,30x20,0,41,54],"
        "70x60,31,0[70x24,31,0,50,70x36,31,26,55],"
        "100x60,101,0[100x45,101,0,51,100x10,101,46,52,100x5,101,56,56]}"
    )
    window_data = [
        {
            "identity": "window",
            "number": 0,
            "title": "window",
            "postfix": "~-",
            "layout": window_layout,
            "panes": [
                {"identity": "pane0", "number": 0},
                {"identity": "pane1", "number": 1, "parent": "pane0"},
                {
                    "identity": "pane2",
                    "number": 2,
                    "parent": "pane1",
                    "command": "cat test.txt",
                },
                {"identity": "pane3", "number": 3, "parent": "pane0"},
                {
                    "identity": "pane4",
                    "number": 4,
                    "parent": "pane3",
                    "command": 'echo "hello world"',
                },
                {"identity": "pane5", "number": 5, "parent": "pane3"},
                {"identity": "pane6", "number": 6, "parent": "pane5"},
                {
                    "identity": "pane7",
                    "number": 7,
                    "parent": "pane6",
                    "command": "htop",
                },
            ],
        }
    ]

    window_list = set_session_parameters(
        DEFAULT_SESSION, DEFAULT_DIRECTORY, window_data,
    )

    scripter = TmuxScripter(DEFAULT_SESSION, DEFAULT_DIRECTORY).set_terminal_size(
        TERMINAL_WIDTH, TERMINAL_HEIGHT
    )
    scripter.analyze(window_list)

    expected = convert_lines_to_object(
        GENERIC_START
        + [
            'split-window -h -t session:0.0 -c "/home/brett" \\; \\',
            'split-window -h -t session:0.1 -c "/home/brett" \\; \\',
            'split-window -v -t session:0.0 -c "/home/brett" \\; \\',
            'split-window -v -t session:0.1 -c "/home/brett" \\; \\',
            'send-keys "cat test.txt" "C-m" \\; \\',
            'split-window -v -t session:0.3 -c "/home/brett" \\; \\',
            'send-keys "echo \\"hello world\\"" "C-m" \\; \\',
            'split-window -v -t session:0.5 -c "/home/brett" \\; \\',
            'split-window -v -t session:0.6 -c "/home/brett" \\; \\',
            'send-keys "htop" "C-m" \\; \\',
            "resize-pane -t session:0.0 -x 30 -y 10 \\; \\",
            "resize-pane -t session:0.3 -x 70 -y 24 \\; \\",
            "resize-pane -t session:0.5 -x 100 -y 45 \\; \\",
            "resize-pane -t session:0.1 -x 30 -y 30 \\; \\",
            "resize-pane -t session:0.2 -x 30 -y 20 \\; \\",
            "resize-pane -t session:0.4 -x 70 -y 36 \\; \\",
            "resize-pane -t session:0.6 -x 100 -y 10 \\; \\",
            "resize-pane -t session:0.7 -x 100 -y 5",
            "popd",
        ]
    )
    actual = convert_lines_to_object(scripter.commands.split("\n"))

    assert_objects_equal(expected, actual, expected.keys(), capsys)
Пример #26
0
def test_many_hard_panes(capsys):
    """
    Test creation of a bunch of complex windows
    """
    # Expected result:
    #  w0p0 (0) | w0p1 (2) |
    #  -------- | -------- | w0p2 (4)
    #  w0p3 (1) | w0p4 (3) |
    builder = TmuxBuilder("session", "/var")
    builder.add_window("w0", "w0p0", "w0")
    builder.add_pane("w0p1", SPLIT_HORIZONTAL)
    builder.add_pane("w0p2", SPLIT_HORIZONTAL)
    builder.add_pane("w0p3", SPLIT_VERTICAL, split_from="w0p0")
    # Will actually be split from pane #2, since the one before this was inserted after pane #0
    # Which causes pane #1 to become pane #2
    builder.add_pane("w0p4", SPLIT_VERTICAL, split_from="w0p1")

    # Expected result:
    #  w1p0 (0) |      w1p1 (2)       |
    #  -------- | ------------------- | w1p2 (5)
    #  w1p3 (1) | w1p4 (3) | w1p5 (4) |
    builder.add_window("w1", "w1p0", "w1")
    builder.add_pane("w1p1", SPLIT_HORIZONTAL)
    builder.add_pane("w1p2", SPLIT_HORIZONTAL)
    builder.add_pane("w1p3", SPLIT_VERTICAL, split_from="w1p0")
    # Will actually be split from pane #2,
    # since the one before this was inserted after pane #0
    # Which causes pane #1 to become pane #2
    builder.add_pane("w1p4", SPLIT_VERTICAL, split_from="w1p1")
    builder.add_pane("w1p5", SPLIT_HORIZONTAL)

    # Expected result:
    #          | w2p3 (1)
    # w2p0 (0) | --------
    #          | w2p4 (2)
    # -------------------
    #      w2p1 (3)
    # -------------------
    # w2p2 (4) | w2p5 (5)
    builder.add_window("w2", "w2p0", "w2")
    builder.add_pane("w2p1", SPLIT_VERTICAL)
    builder.add_pane("w2p2", SPLIT_VERTICAL)
    builder.add_pane("w2p3", SPLIT_HORIZONTAL, split_from="w2p0")
    builder.add_pane("w2p4", SPLIT_VERTICAL)
    # This is split from pane #3 since the top pane was split once
    builder.add_pane("w2p5", SPLIT_HORIZONTAL, split_from="w2p2")

    # Expected result:
    #          | w3p1 (1) | w3p3 (2)
    # w3p0 (0) | -------------------
    #          |      w3p2 (3)
    builder.add_window("w3", "w3p0", "w3")
    builder.add_pane("w3p1", SPLIT_HORIZONTAL)
    builder.add_pane("w3p2", SPLIT_VERTICAL, split_from="w3p1")
    builder.add_pane("w3p3", SPLIT_HORIZONTAL, split_from="w3p1")

    actual = convert_lines_to_object(builder.build().split("\n"))

    expected = convert_lines_to_object(
        [
            'pushd "/var"',
            "tmux new-session -d -s session \\; \\",
            "rename-window w0 \\; \\",
            'split-window -h -c "/var" \\; \\',
            'split-window -h -c "/var" \\; \\',
            'split-window -v -t session:0.0 -c "/var" \\; \\',
            'split-window -v -t session:0.2 -c "/var" \\; \\',
            'new-window -n w1 -c "/var" \\; \\',
            'split-window -h -c "/var" \\; \\',
            'split-window -h -c "/var" \\; \\',
            'split-window -v -t session:1.0 -c "/var" \\; \\',
            'split-window -v -t session:1.2 -c "/var" \\; \\',
            'split-window -h -c "/var" \\; \\',
            'new-window -n w2 -c "/var" \\; \\',
            'split-window -v -c "/var" \\; \\',
            'split-window -v -c "/var" \\; \\',
            'split-window -h -t session:2.0 -c "/var" \\; \\',
            'split-window -v -c "/var" \\; \\',
            'split-window -h -t session:2.3 -c "/var" \\; \\',
            'new-window -n w3 -c "/var" \\; \\',
            'split-window -h -c "/var" \\; \\',
            'split-window -v -t session:3.1 -c "/var" \\; \\',
            'split-window -h -t session:3.1 -c "/var"',
            "popd",
        ]
    )
    assert_objects_equal(expected, actual, expected.keys(), capsys)
Пример #27
0
def test_vertical_tri_split_with_hitch(capsys):
    """
    A complex vertical layout with nine panes

     0 | 1 | 2
    -----------
       3 | 4
    -----------
       | 6 |
     5 |---| 8
       | 7 |
    """

    window_layout = (
        # Top set
        "32ff,200x60,0,0[200x12,0,0{30x12,0,0,49,50x12,31,0,53,120x12,81,0,54},"
        # Second set
        "200x18,0,31{150x18,0,31,50,50x18,151,31,55},"
        # First pane of third set
        "200x30,0,31{100x30,0,31,51,60x30,101,46"
        # Second group and third pane of bottom set
        "[60x10,101,31,52,60x20,101,41,57],40x30,161,31,56}]"
    )
    window_data = [
        {
            "identity": "window",
            "number": 0,
            "title": "window",
            "postfix": "~-",
            "layout": window_layout,
            "panes": [
                {"identity": "pane0", "number": 0},
                {"identity": "pane1", "number": 1, "parent": "pane0"},
                {"identity": "pane2", "number": 2, "parent": "pane1"},
                {"identity": "pane3", "number": 3, "parent": "pane0"},
                {"identity": "pane4", "number": 4, "parent": "pane3"},
                {"identity": "pane5", "number": 5, "parent": "pane3"},
                {"identity": "pane6", "number": 6, "parent": "pane5"},
                {
                    "identity": "pane7",
                    "number": 7,
                    "parent": "pane6",
                    "command": "htop",
                },
                {"identity": "pane8", "number": 8, "parent": "pane6",},
            ],
        }
    ]

    window_list = set_session_parameters(
        DEFAULT_SESSION, DEFAULT_DIRECTORY, window_data,
    )

    scripter = TmuxScripter(DEFAULT_SESSION, DEFAULT_DIRECTORY).set_terminal_size(
        TERMINAL_WIDTH, TERMINAL_HEIGHT
    )
    scripter.analyze(window_list)

    expected = convert_lines_to_object(
        GENERIC_START
        + [
            'split-window -v -t session:0.0 -c "/home/brett" \\; \\',
            'split-window -v -t session:0.1 -c "/home/brett" \\; \\',
            'split-window -h -t session:0.0 -c "/home/brett" \\; \\',
            'split-window -h -t session:0.1 -c "/home/brett" \\; \\',
            'split-window -h -t session:0.3 -c "/home/brett" \\; \\',
            'split-window -h -t session:0.5 -c "/home/brett" \\; \\',
            'split-window -h -t session:0.6 -c "/home/brett" \\; \\',
            'split-window -v -t session:0.6 -c "/home/brett" \\; \\',
            'send-keys "htop" "C-m" \\; \\',
            "resize-pane -t session:0.0 -x 30 -y 12 \\; \\",
            "resize-pane -t session:0.3 -x 150 -y 18 \\; \\",
            "resize-pane -t session:0.5 -x 100 -y 30 \\; \\",
            "resize-pane -t session:0.1 -x 50 -y 12 \\; \\",
            "resize-pane -t session:0.2 -x 120 -y 12 \\; \\",
            "resize-pane -t session:0.4 -x 50 -y 18 \\; \\",
            "resize-pane -t session:0.6 -x 60 -y 10 \\; \\",
            "resize-pane -t session:0.8 -x 40 -y 30 \\; \\",
            "resize-pane -t session:0.7 -x 60 -y 20",
            "popd",
        ]
    )
    actual = convert_lines_to_object(scripter.commands.split("\n"))

    assert_objects_equal(expected, actual, expected.keys(), capsys)
Пример #28
0
def test_nested_split(capsys):
    """
    Tests a layout which has nested splits

      0  |  2  |
     --- | --- | 4
      1  |  3  |
    """

    window_layout = (
        "32ff,200x60,0,0{100x60,0,0[100x30,0,0,49,100x30,0,31,53],50x60,119,0"
        "[50x30,101,0,51,50x30,101,31,52],50x60,151,0,51}"
    )
    window_data = [
        {
            "identity": "window",
            "number": 0,
            "title": "window",
            "postfix": "~-",
            "layout": window_layout,
            "panes": [
                {"identity": "pane0", "number": 0, "command": "top"},
                {"identity": "pane1", "number": 1, "parent": "pane0"},
                {"identity": "pane2", "number": 2, "parent": "pane0"},
                {
                    "identity": "pane3",
                    "number": 3,
                    "parent": "pane2",
                    "command": "tail -f foo.txt",
                },
                {
                    "identity": "pane4",
                    "number": 4,
                    "parent": "pane2",
                    "command": "tail -f test.txt",
                },
            ],
        }
    ]

    window_list = set_session_parameters(
        DEFAULT_SESSION, DEFAULT_DIRECTORY, window_data,
    )

    scripter = TmuxScripter(DEFAULT_SESSION, DEFAULT_DIRECTORY).set_terminal_size(
        TERMINAL_WIDTH, TERMINAL_HEIGHT
    )
    scripter.analyze(window_list)

    expected = convert_lines_to_object(
        GENERIC_START
        + [
            'send-keys "top" "C-m" \\; \\',
            'split-window -h -t session:0.0 -c "/home/brett" \\; \\',
            'split-window -h -t session:0.1 -c "/home/brett" \\; \\',
            'send-keys "tail -f test.txt" "C-m" \\; \\',
            'split-window -v -t session:0.0 -c "/home/brett" \\; \\',
            'split-window -v -t session:0.2 -c "/home/brett" \\; \\',
            'send-keys "tail -f foo.txt" "C-m" \\; \\',
            "resize-pane -t session:0.0 -x 100 -y 30 \\; \\",
            "resize-pane -t session:0.2 -x 50 -y 30 \\; \\",
            "resize-pane -t session:0.4 -x 50 -y 60 \\; \\",
            "resize-pane -t session:0.1 -x 100 -y 30 \\; \\",
            "resize-pane -t session:0.3 -x 50 -y 30",
            "popd",
        ]
    )
    actual = convert_lines_to_object(scripter.commands.split("\n"))

    assert_objects_equal(expected, actual, expected.keys(), capsys)