-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor BraggTree test to use pytest-qt
- Loading branch information
1 parent
d5dd42a
commit 81f2a56
Showing
1 changed file
with
20 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,27 @@ | ||
from __future__ import absolute_import, print_function | ||
import unittest | ||
from qtpy.QtWidgets import QApplication | ||
import pytest | ||
from addie.main import MainWindow | ||
from addie.rietveld.braggtree import BraggTree, BankRegexException | ||
|
||
@pytest.fixture | ||
def braggtree(): | ||
return BraggTree(None) | ||
|
||
class BraggTreeTests(unittest.TestCase): | ||
def setUp(self): | ||
self.main_window = QApplication([]) | ||
|
||
def tearDown(self): | ||
self.main_window.quit() | ||
def test_get_bank_id(qtbot, braggtree): | ||
"""Test we can extract a bank id from bank workspace name""" | ||
target = 12345 | ||
bank_wksp_name = "Bank {} - 90.0".format(target) | ||
bank_id = braggtree._get_bank_id(bank_wksp_name) | ||
assert int(bank_id) == target | ||
|
||
def test_get_bank_id(self): | ||
"""Test we can extract a bank id from bank workspace name""" | ||
braggtree = BraggTree(None) | ||
target = 12345 | ||
bank_wksp_name = "Bank {} - 90.0".format(target) | ||
bank_id = braggtree._get_bank_id(bank_wksp_name) | ||
self.assertEqual(int(bank_id), target) | ||
def test_get_bank_id_exception(qtbot, braggtree): | ||
"""Test for raised exception from a bad workspace name""" | ||
bad_ws = "Bank jkl 1 -- 90.0" | ||
with pytest.raises(BankRegexException) as e: | ||
braggtree._get_bank_id(bad_ws) | ||
|
||
def test_get_bank_id_exception(self): | ||
"""Test for raised exception from a bad workspace name""" | ||
braggtree = BraggTree(None) | ||
bad_ws = "Bank jkl 1 -- 90.0" | ||
self.assertRaises(BankRegexException, braggtree._get_bank_id, bad_ws) | ||
|
||
def test_do_plot_ws_exception(self): | ||
"""Test for raised exception from MainWindow==None""" | ||
braggtree = BraggTree(None) | ||
self.assertRaises(NotImplementedError, braggtree.do_plot_ws) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() # pragma: no cover | ||
def test_do_plot_ws_exception(qtbot, braggtree): | ||
"""Test for raised exception from MainWindow==None""" | ||
with pytest.raises(NotImplementedError) as e: | ||
braggtree.do_plot_ws() |