File: test_switch_workspace.py

package info (click to toggle)
librepcb 1.2.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 58,484 kB
  • sloc: cpp: 267,986; python: 12,100; ansic: 6,899; xml: 234; sh: 215; makefile: 115; perl: 73
file content (77 lines) | stat: -rw-r--r-- 3,562 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
Test the "Initialize Workspace Wizard" in the Control Panel to switch to
a different workspace
"""

import os
import shutil


def test_create_new_workspace(librepcb, helpers):
    """
    Choose a non-existent workspace path to create a new workspace
    """
    test_workspace_path = librepcb.workspace_path + '-test'
    with librepcb.open() as app:
        # Open "Switch Workspace" dialog.
        app.widget('controlPanel').properties()['visible'] is True
        app.action('controlPanelActionSwitchWorkspace').trigger(blocking=False)
        wizard = app.widget('controlPanelInitWorkspaceWizard')

        # Choose workspace path.
        path_edit = app.widget('controlPanelInitWorkspaceWizardChooseWorkspacePathEdit')
        assert path_edit.properties()['text'] == librepcb.workspace_path
        status_label = app.widget('controlPanelInitWorkspaceWizardChooseWorkspaceStatusLabel')
        assert 'contains a valid workspace' in status_label.properties()['text']
        path_edit.set_property('text', test_workspace_path)
        assert 'workspace will be created' in status_label.properties()['text']
        app.widget('controlPanelInitWorkspaceWizardNextButton').click()

        # Choose workspace settings.
        user_edit = app.widget('controlPanelInitWorkspaceWizardChooseSettingsUserNameEdit')
        user_edit.set_property('text', 'foobar 1337')
        app.widget('controlPanelInitWorkspaceWizardFinishButton').click()

        # Verify that the workspace has been created.
        helpers.wait_until_widget_hidden(wizard)
        assert os.path.exists(os.path.join(test_workspace_path,
                                           '.librepcb-workspace'))

    # Open LibrePCB again to see if the workspace is automatically opened
    # and the settings are applied.
    with librepcb.open() as app:
        app.widget('controlPanel').properties()['visible'] is True
        app.action('controlPanelActionOpenWorkspaceSettings').trigger(blocking=False)
        user_edit = app.widget('controlPanelWorkspaceSettingsDialogGeneralUserNameEdit')
        assert user_edit.properties()['text'] == 'foobar 1337'


def test_open_compatible_workspace(librepcb, helpers):
    """
    Choose a compatible workspace to open
    """
    test_workspace_path = librepcb.workspace_path + '-test'
    shutil.copytree(librepcb.workspace_path, test_workspace_path)
    with librepcb.open() as app:
        # Open "Switch Workspace" dialog.
        app.widget('controlPanel').properties()['visible'] is True
        app.action('controlPanelActionSwitchWorkspace').trigger(blocking=False)
        wizard = app.widget('controlPanelInitWorkspaceWizard')

        # Choose workspace path.
        path_edit = app.widget('controlPanelInitWorkspaceWizardChooseWorkspacePathEdit')
        assert path_edit.properties()['text'] == librepcb.workspace_path
        status_label = app.widget('controlPanelInitWorkspaceWizardChooseWorkspaceStatusLabel')
        assert 'contains a valid workspace' in status_label.properties()['text']
        path_edit.set_property('text', test_workspace_path)
        assert 'contains a valid workspace' in status_label.properties()['text']
        app.widget('controlPanelInitWorkspaceWizardFinishButton').click()
        helpers.wait_until_widget_hidden(wizard)

    # Open LibrePCB again to see if the workspace is automatically opened.
    shutil.rmtree(librepcb.workspace_path)
    with librepcb.open() as app:
        app.widget('controlPanel').properties()['visible'] is True