madscatt / zazmol

Library for defining molecular objects to create simulation and analysis programs To install: python setup.py install dependencies: numpy, mocker
GNU General Public License v3.0
0 stars 2 forks source link

Migrate tests to Python 3 #70

Closed madscatt closed 1 year ago

madscatt commented 1 year ago

Mocker (python 2.7) had been replaced with Mock. Evaluate syntax and alter all tests so they work in Python 3.

Note, for now, we will write our tests using unittest as it is part of Python 3 and Pytest would be a non-standard, though widely used, dependency. Pytest does run the unittest code without modification.

madscatt commented 1 year ago

import unittest

instead of passing MockerTestCase to class X, pass unittest.TestCase

remove

from mocker import Mocker, MockerTestCase

also don't forget to use "with io.open" instead of open otherwise tests will return a ResourceWarning message.

add:

if name == 'main': (note that Markdown removes the double underscores around name and main here)

unittest.main()

to the end of all tests

madscatt commented 1 year ago

Note: test_null for test_unit_calculate_Prop_calccom returned an error as numpy.zeros was called with float number of dimensions instead of int.

madscatt commented 1 year ago

Note that import warnings ; warnings.filterwarnings('ignore') no longer works in global scope, needs to be in setUp method (see: test_unit_calculate_Prop_calccom.py). T

madscatt commented 1 year ago

test_unit_calculate_Prop_calcpmi.py needs self.m = Mocker() to function

from unittest.mock import MagicMock

then for the specific mock in this specific file, since ARGS is not implemented in the same was as Mocker (2.7)

self.m = MagicMock() operate.Move.center(ARGS) needs to be operate.Move.center

madscatt commented 1 year ago

Use python -m unittest discover to test all test_* files in a directory

madscatt commented 1 year ago

656 tests converted to Python 3 ... all pass.