From 695e679e66e2331b6e6c23c70e983addf555ec38 Mon Sep 17 00:00:00 2001 From: Benjamin Morgan Date: Tue, 2 May 2017 07:21:21 +0100 Subject: [PATCH] 3.6+ compatible tests rewritten for 3.5.0 compatibility Mock methods such as Mock.assert_called_once() are new in 3.6.0. For compatibility with 3.5+ these have been replaced with e.g. assertEqual( Mock.call_count, 1 ) --- tests/test_lookup_table.py | 2 +- tests/test_simulation.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/test_lookup_table.py b/tests/test_lookup_table.py index c18f268..90dd2b3 100644 --- a/tests/test_lookup_table.py +++ b/tests/test_lookup_table.py @@ -36,7 +36,7 @@ def test_nearest_neighbour_lookup_table_is_initialised( self, mock_generate_near self.assertEqual( lookup_table.cn_energy, 'baz' ) self.assertEqual( lookup_table.connected_site_pairs, 'qux' ) self.assertEqual( lookup_table.site_specific_coordination_per_site, 'quux' ) - mock_generate_nearest_neighbour_lookup_table.assert_called_once() + self.assertEqual( mock_generate_nearest_neighbour_lookup_table.call_count, 1 ) def test_lookup_table_init_with_invalid_hamiltonian_keywork_raises_ValueError( self ): hamiltonian = 'foo' diff --git a/tests/test_simulation.py b/tests/test_simulation.py index 54a887d..4468720 100644 --- a/tests/test_simulation.py +++ b/tests/test_simulation.py @@ -23,9 +23,9 @@ def test_reset( self ): simulation.atoms = Mock( spec=Species ) simulation.atoms.atoms = [ Mock( spec=Atom ), Mock( spec=Atom ) ] simulation.reset() - simulation.lattice.reset.assert_called() - simulation.atoms.atoms[0].reset.assert_called() - simulation.atoms.atoms[1].reset.assert_called() + self.assertEqual( simulation.lattice.reset.call_count, 1 ) + self.assertEqual( simulation.atoms.atoms[0].reset.call_count, 1 ) + self.assertEqual( simulation.atoms.atoms[1].reset.call_count, 1 ) def test_set_number_of_atoms( self ): simulation = Simulation() @@ -144,7 +144,7 @@ def test_run_with_equilibration_steps( self ): simulation.number_of_jumps = 30 simulation.run() self.assertEqual( simulation.lattice.jump.call_count, 20+30 ) - simulation.reset.assert_called() + self.assertEqual( simulation.reset.call_count, 1 ) class SimulationResultsTestCase( unittest.TestCase ):