1# Copyright (c) 2011 Florian Mounier
2# Copyright (c) 2012, 2014 Tycho Andersen
3# Copyright (c) 2013 Craig Barnes
4# Copyright (c) 2014 Sean Vig
5#
6# Permission is hereby granted, free of charge, to any person obtaining a copy
7# of this software and associated documentation files (the "Software"), to deal
8# in the Software without restriction, including without limitation the rights
9# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10# copies of the Software, and to permit persons to whom the Software is
11# furnished to do so, subject to the following conditions:
12#
13# The above copyright notice and this permission notice shall be included in
14# all copies or substantial portions of the Software.
15#
16# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22# SOFTWARE.
23
24import random
25import pytest
26import libqtile.config
27from libqtile import layout
28from libqtile.confreader import Config
29
30class GroupConfig(Config):
31    auto_fullscreen = True
32    groups = [
33        libqtile.config.Group("a")
34    ]
35    layouts = [
36        layout.Max()
37    ]
38    floating_layout = libqtile.resources.default_config.floating_layout
39    keys = []
40    mouse = []
41    screens = []
42
43
44group_config = pytest.mark.parametrize("manager", [GroupConfig], indirect=True)
45
46
47@group_config
48def test_window_order(manager):
49    # windows to add
50    windows_name = ["one","two","three","four","five","six","seven","eight","nine","ten"]
51    windows = {}
52
53    # Add windows one by one
54    for win in windows_name:
55        windows[win] = manager.test_window(win)
56
57    # Winmust be sotred in the same order as they were created
58    assert windows_name == manager.c.group.info()["windows"]
59
60    # Randomly remove 5 windows and see if orders remains persistant
61    for i in range(5):
62        win_to_remove = random.choice(windows_name)
63        windows_name.remove(win_to_remove)
64        manager.kill_window(windows[win_to_remove])
65        del windows[win_to_remove]
66        assert windows_name == manager.c.group.info()["windows"]
67