File: test_existing_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 (105 lines) | stat: -rw-r--r-- 4,293 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
Test the "Initialize Workspace Wizard" on an existing installation, i.e.
with a workspace already set in the user settings
"""

import os
import pytest
import shutil
import sys


@pytest.mark.xfail(sys.platform == 'darwin', raises=AssertionError,
                   strict=False, reason="Flaky on macOS, no idea why.")
def test_upgrade_v01(librepcb, helpers):
    """
    Test an upgrade which copies from 'v0.1' to 'data'
    """
    v01_path = os.path.join(librepcb.workspace_path, 'v0.1')
    data_path = os.path.join(librepcb.workspace_path, 'data')
    shutil.rmtree(data_path)
    with librepcb.open() as app:
        # Perform upgrade.
        wizard = app.widget('initWorkspaceWizard')
        src_label = app.widget('initWorkspaceWizardUpgradeSourceLabel')
        assert v01_path in src_label.properties()['text']
        dst_label = app.widget('initWorkspaceWizardUpgradeDestinationLabel')
        assert data_path in dst_label.properties()['text']
        app.widget('initWorkspaceWizardFinishButton').click()

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

        # Verify that the control panel is now opened.
        app.widget('controlPanel').properties()['visible'] is True

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


@pytest.mark.xfail(sys.platform == 'darwin', raises=AssertionError,
                   strict=False, reason="Flaky on macOS, no idea why.")
def test_upgrade_data(librepcb, helpers):
    """
    Test an upgrade which copies from 'data' to 'v0.1'
    """
    v01_path = os.path.join(librepcb.workspace_path, 'v0.1')
    data_path = os.path.join(librepcb.workspace_path, 'data')
    shutil.rmtree(v01_path)
    os.remove(os.path.join(data_path, '.librepcb-data'))  # Downgrade to v0.1
    with librepcb.open() as app:
        # Perform upgrade.
        wizard = app.widget('initWorkspaceWizard')
        src_label = app.widget('initWorkspaceWizardUpgradeSourceLabel')
        assert data_path in src_label.properties()['text']
        dst_label = app.widget('initWorkspaceWizardUpgradeDestinationLabel')
        assert v01_path in dst_label.properties()['text']
        app.widget('initWorkspaceWizardFinishButton').click()

        # Verify that the v0.1 directory has been created and the data
        # directory has been upgraded.
        helpers.wait_until_widget_hidden(wizard)
        assert os.path.exists(v01_path)
        assert os.path.exists(os.path.join(data_path, '.librepcb-data'))

        # Verify that the control panel is now opened.
        app.widget('controlPanel').properties()['visible'] is True

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


def test_downgrade(librepcb, helpers):
    """
    Test opening a workspace which needs to be initialized with an
    older file format
    """
    v01_path = os.path.join(librepcb.workspace_path, 'v0.1')
    v02_path = os.path.join(librepcb.workspace_path, 'v1')
    data_path = os.path.join(librepcb.workspace_path, 'data')
    shutil.rmtree(v01_path)
    with open(os.path.join(data_path, '.librepcb-data'), 'wb') as f:
        f.write(b'999\n')
    with librepcb.open() as app:
        # Choose workspace settings.
        wizard = app.widget('initWorkspaceWizard')
        user_edit = app.widget('initWorkspaceWizardChooseSettingsUserNameEdit')
        user_edit.set_property('text', 'foobar 42')
        app.widget('initWorkspaceWizardFinishButton').click()

        # Verify that the v1 directory has been created.
        helpers.wait_until_widget_hidden(wizard)
        assert os.path.exists(os.path.join(v02_path, '.librepcb-data'))

        # Verify that the control panel is now opened.
        app.widget('controlPanel').properties()['visible'] is True

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