Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
matrss committed Feb 27, 2024
1 parent 236a5a7 commit 64e1916
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 20 deletions.
9 changes: 8 additions & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ def generate_initial_config():
examples = DataFiles(data_fs=constants.DATA_FS,
server_config_fs=constants.SERVER_CONFIG_FS)
examples.create_server_config(detailed_information=True)
examples.create_data()
if constants.DATA_FS.isempty("/"):
examples.create_data()

if not constants.SERVER_CONFIG_FS.exists(constants.MSCOLAB_CONFIG_FILE):
config_string = f'''
Expand Down Expand Up @@ -220,9 +221,15 @@ def reset_config():
"""Reset the configuration directory used in the tests (tests.constants.ROOT_FS) after every test
"""
# Ideally this would just be constants.ROOT_FS.removetree("/"), but SQLAlchemy complains if the SQLite file is deleted.
# Also, on Windows there are issues with files in msui/testdata being held open in another process, so those are
# excluded as well. This shouldn't be a problem since they are meant to be static anyway.
for e in constants.ROOT_FS.walk.files(exclude=["mscolab.db"]):
if fs.path.isbase("/msui/testdata", e):
continue
constants.ROOT_FS.remove(e)
for e in constants.ROOT_FS.walk.dirs(search="depth"):
if e == "/msui" or fs.path.isbase("/msui/testdata", e):
continue
constants.ROOT_FS.removedir(e)

generate_initial_config()
Expand Down
5 changes: 5 additions & 0 deletions tests/_test_msui/test_mscolab.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
limitations under the License.
"""
import os
import sys
import fs
import fs.errors
import fs.opener.errors
Expand Down Expand Up @@ -350,6 +351,10 @@ def test_handle_export(self, mockbox, qtbot):
for i in range(wp_count):
assert exported_waypoints.waypoint_data(i).lat == self.window.mscolab.waypoints_model.waypoint_data(i).lat

@pytest.mark.skipif(
sys.platform == "darwin",
reason="This test is flaky on MacOS because of some cleanup error in temporary files.",
)
@pytest.mark.parametrize("name", [("example.ftml", "actionImportFlightTrackFTML", 5),
("example.csv", "actionImportFlightTrackCSV", 5),
("example.txt", "actionImportFlightTrackTXT", 5),
Expand Down
41 changes: 26 additions & 15 deletions tests/_test_msui/test_mscolab_version_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,17 @@ def assert_():
assert len_prev == (len_after - 2)
qtbot.wait_until(assert_)

@mock.patch("PyQt5.QtWidgets.QInputDialog.getText", return_value=["MyVersionName", True])
def test_set_version_name(self, mockbox):
self._set_version_name()
assert self.version_window.changes.currentItem().version_name == "MyVersionName"
assert self.version_window.changes.count() == 1

@mock.patch("PyQt5.QtWidgets.QInputDialog.getText", return_value=["MyVersionName", True])
def test_version_name_delete(self, mockbox):
self._set_version_name()
assert self.version_window.changes.currentItem().version_name == "MyVersionName"
def test_set_version_name(self, qtbot):
self._set_version_name(qtbot)

def test_version_name_delete(self, qtbot):
self._set_version_name(qtbot)
QtTest.QTest.mouseClick(self.version_window.deleteVersionNameBtn, QtCore.Qt.LeftButton)
assert self.version_window.changes.count() == 1
assert self.version_window.changes.currentItem().version_name is None

def assert_():
assert self.version_window.changes.count() == 1
assert self.version_window.changes.currentItem().version_name is None
qtbot.wait_until(assert_)

@mock.patch("PyQt5.QtWidgets.QMessageBox.question", return_value=QtWidgets.QMessageBox.Yes)
def test_undo_changes(self, mockbox, qtbot):
Expand Down Expand Up @@ -159,10 +157,23 @@ def _change_version_filter(self, index):
self.version_window.versionFilterCB.setCurrentIndex(index)
self.version_window.versionFilterCB.currentIndexChanged.emit(index)

def _set_version_name(self):
def _set_version_name(self, qtbot):
self._change_version_filter(1)
num_changes_before = self.version_window.changes.count()
# make a changes
self.window.mscolab.waypoints_model.invert_direction()
self.version_window.load_all_changes()

# Ensure that the change is visible
def assert_():
self.version_window.load_all_changes()
assert self.version_window.changes.count() == num_changes_before + 1
qtbot.wait_until(assert_)

self._activate_change_at_index(0)
QtTest.QTest.mouseClick(self.version_window.nameVersionBtn, QtCore.Qt.LeftButton)
with mock.patch("PyQt5.QtWidgets.QInputDialog.getText", return_value=["MyVersionName", True]):
QtTest.QTest.mouseClick(self.version_window.nameVersionBtn, QtCore.Qt.LeftButton)

# Ensure that the name change is fully processed
def assert_():
assert self.version_window.changes.currentItem().version_name == "MyVersionName"
qtbot.wait_until(assert_)
6 changes: 3 additions & 3 deletions tests/_test_msui/test_topview.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,13 @@ def query_server(self, url):
QtTest.QTest.mouseClick(self.wms_control.multilayers.btGetCapabilities, QtCore.Qt.LeftButton)
wait_until_signal(self.wms_control.cpdlg.canceled)

def test_server_getmap(self):
def test_server_getmap(self, qtbot):
"""
assert that a getmap call to a WMS server displays an image
"""
self.query_server(self.url)
QtTest.QTest.mouseClick(self.wms_control.btGetMap, QtCore.Qt.LeftButton)
wait_until_signal(self.wms_control.image_displayed)
with qtbot.wait_signal(self.wms_control.image_displayed):
QtTest.QTest.mouseClick(self.wms_control.btGetMap, QtCore.Qt.LeftButton)
assert self.window.getView().map.image is not None
self.window.getView().set_settings({})
self.window.getView().clear_figure()
Expand Down
14 changes: 13 additions & 1 deletion tests/_test_mswms/test_wms.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
See the License for the specific language governing permissions and
limitations under the License.
"""

import sys
import os
from shutil import move

Expand Down Expand Up @@ -388,6 +388,12 @@ def test_import_error(self):
assert mslib.mswms.wms.mswms_settings.__file__ is not None
assert mslib.mswms.wms.mswms_auth.__file__ is not None

@pytest.mark.skipif(
sys.platform == "darwin",
reason="There is a race condition between modifying with ncap2 and asserting that the file changed where the"
" server might not see the change before the request is made, which leads to a failure of the following"
" assert.",
)
def test_files_changed(self):
def do_test():
environ = {
Expand Down Expand Up @@ -429,6 +435,12 @@ def do_test():
"data_access", new=watch_access):
do_test()

@pytest.mark.skipif(
sys.platform == "darwin",
reason="Changes global variables (e.g. DOCS_LOCATION) which can affect other tests depending on test order"
" (e.g. tests/_test_mswms/test_mss_plot_driver.py::Test_VSec::test_VS_gallery_template fails consistently in"
" reverse order on MacOS 14).",
)
def test_gallery(self, tmpdir):
tempdir = tmpdir.mkdir("static")
docsdir = tmpdir.mkdir("docs")
Expand Down

0 comments on commit 64e1916

Please sign in to comment.