def test_raise_exception_file_not_exists(self): fake_path_class = MagicMock(spec=Path) fake_path = fake_path_class.return_value fake_path.__str__.return_value = 'CMakeLists.txt' fake_path.exists.return_value = False with self.assertRaises(VersionError): CMakeVersionCommand(cmake_lists_path=fake_path)
def test_should_call_print_current_version_without_raising_exception(self): fake_path_class = MagicMock(spec=Path) fake_path = fake_path_class.return_value fake_path.__str__.return_value = 'CMakeLists.txt' fake_path.exists.return_value = True fake_path.read_text.return_value = "project(VERSION 21)" CMakeVersionCommand(cmake_lists_path=fake_path).run(args=['show']) fake_path.read_text.assert_called_with()
def test_return_0_correct_version_on_verify(self): fake_path_class = MagicMock(spec=Path) fake_path = fake_path_class.return_value fake_path.__str__.return_value = 'CMakeLists.txt' fake_path.exists.return_value = True fake_path.read_text.return_value = "" result = CMakeVersionCommand(cmake_lists_path=fake_path).run( args=['verify', '21.4']) self.assertEqual(0, result)
def test_raise_exception_no_project(self): fake_path_class = MagicMock(spec=Path) fake_path = fake_path_class.return_value fake_path.__str__.return_value = 'CMakeLists.txt' fake_path.exists.return_value = True fake_path.read_text.return_value = "" with self.assertRaises(ValueError): CMakeVersionCommand(cmake_lists_path=fake_path).run(args=['show']) fake_path.read_text.assert_called_with()
def test_raise_update_version(self): fake_path_class = MagicMock(spec=Path) fake_path = fake_path_class.return_value fake_path.__str__.return_value = 'CMakeLists.txt' fake_path.exists.return_value = True fake_path.read_text.return_value = "project(VERSION 21)" CMakeVersionCommand(cmake_lists_path=fake_path).run( args=['update', '22']) fake_path.read_text.assert_called_with() fake_path.write_text.assert_called_with('project(VERSION 22)')
def test_return_error_string_incorrect_version_on_verify(self): fake_path_class = MagicMock(spec=Path) fake_path = fake_path_class.return_value fake_path.__str__.return_value = 'CMakeLists.txt' fake_path.exists.return_value = True fake_path.read_text.return_value = "" result = CMakeVersionCommand(cmake_lists_path=fake_path).run( args=['verify', 'su_much_version_so_much_wow']) self.assertTrue(isinstance(result, str), "expected result to be an error string")