From b9a7a3df167e2d9fdd19cb00d375d8995855b281 Mon Sep 17 00:00:00 2001 From: Benda Xu Date: Tue, 31 Jan 2023 23:35:59 +0800 Subject: [PATCH] test_{samples,calculator}.py: migrate from nose to pytest. Description: nose is an obsoleted testing framework for Python, dead and unmaintained since 2015 Properly teardown fixtures after the test. Reference: https://bugs.debian.org/1018659 Reference: https://bugs.gentoo.org/878727 Reference: https://github.com/uvemas/ViTables/issues/114 --- tests/test_calculator.py | 15 +++++++++++++ {vitables/test => tests}/test_samples.py | 14 ++++++------ vitables/calculator/test/__init__.py | 0 vitables/calculator/test/test_calculator.py | 24 --------------------- 4 files changed, 22 insertions(+), 31 deletions(-) create mode 100644 tests/test_calculator.py rename {vitables/test => tests}/test_samples.py (97%) delete mode 100644 vitables/calculator/test/__init__.py delete mode 100644 vitables/calculator/test/test_calculator.py diff --git a/tests/test_calculator.py b/tests/test_calculator.py new file mode 100644 index 00000000..d93cb2fb --- /dev/null +++ b/tests/test_calculator.py @@ -0,0 +1,15 @@ +import vitables.calculator.calculator as vtc + + +class TestCalculator: + """Test calculator functionality.""" + + def test_extract_identifiers(self): + """Test function that extract marked identifiers from an expression.""" + empty_set = vtc.extract_identifiers('') + assert len(empty_set) == 0 + assert set(['$data']) == vtc.extract_identifiers('$data') + assert set(['$data']) == vtc.extract_identifiers('+$data*') + assert set(['$data']) == vtc.extract_identifiers('+$data*$data') + assert set(['$data', '$data1']) == vtc.extract_identifiers('+$data*$data1 + test') + assert set(['$data', '$test.data1']) == vtc.extract_identifiers('+$data*$test.data1 + test') diff --git a/vitables/test/test_samples.py b/tests/test_samples.py similarity index 97% rename from vitables/test/test_samples.py rename to tests/test_samples.py index 2631fb10..360e6cf4 100644 --- a/vitables/test/test_samples.py +++ b/tests/test_samples.py @@ -1,10 +1,5 @@ import sys import os.path -import nose.tools as nt - -import sip -sip.setapi('QString', 2) -sip.setapi('QVariant', 2) from qtpy import QtWidgets from qtpy import QtCore @@ -40,7 +35,7 @@ def assert_path(test, path): if not path: return index = get_index(test.model, path[0]) - nt.assert_false(index is None) + assert index is not None test.view.activateNode(index) assert_path(test, path[1:]) @@ -182,11 +177,16 @@ def setup_class(cls): cls.model = cls.vtgui.dbs_tree_model cls.view = cls.vtgui.dbs_tree_view + @classmethod + def teardown_class(cls): + del cls.vtapp + del cls.app + def test_opening_files(self): """Generate tests for given data files.""" for filepath, nodes in self.TEST_NODES.items(): for node in nodes: - yield self.check_node_open, filepath, node + self.check_node_open(filepath, node) def check_node_open(self, filepath, nodepath): """Open file get access to a node and read all cells.""" diff --git a/vitables/calculator/test/__init__.py b/vitables/calculator/test/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/vitables/calculator/test/test_calculator.py b/vitables/calculator/test/test_calculator.py deleted file mode 100644 index 2405eb84..00000000 --- a/vitables/calculator/test/test_calculator.py +++ /dev/null @@ -1,24 +0,0 @@ -import sip -sip.setapi('QString', 2) -sip.setapi('QVariant', 2) - -import nose.tools as nt - -import vitables.calculator.calculator as vtc - - -class TestCalculator: - """Test calculator functionality.""" - - def test_extract_identifiers(self): - """Test function that extract marked identifiers from an expression.""" - empty_set = vtc.extract_identifiers('') - nt.assert_true(len(empty_set) == 0) - nt.assert_equal(set(['$data']), vtc.extract_identifiers('$data')) - nt.assert_equal(set(['$data']), vtc.extract_identifiers('+$data*')) - nt.assert_equal(set(['$data']), - vtc.extract_identifiers('+$data*$data')) - nt.assert_equal(set(['$data', '$data1']), - vtc.extract_identifiers('+$data*$data1 + test')) - nt.assert_equal(set(['$data', '$test.data1']), - vtc.extract_identifiers('+$data*$test.data1 + test'))