def test_failure(self, mock_check_output):
     # A CalledProcessError is raised if the Juju version cannot be found.
     mock_check_output.side_effect = (self.error, self.error)
     with self.assertRaises(subprocess.CalledProcessError) as info:
         juju_version()
     self.assertIs(self.error, info.exception)
     self.assertEqual(2, mock_check_output.call_count)
 def test_pyjuju(self, mock_check_output):
     # The pyJuju version is correctly retrieved.
     mock_check_output.return_value = '0.7.2'
     version = juju_version()
     self.assertEqual(Version(0, 7, 2), version)
     mock_check_output.assert_called_once_with(
         ['juju', '--version'], stderr=subprocess.STDOUT,
     )
 def test_juju_core(self, mock_check_output):
     # The juju-core version is correctly retrieved.
     mock_check_output.side_effect = (self.error, '1.12.3')
     version = juju_version()
     self.assertEqual(Version(1, 12, 3), version)
     self.assertEqual(2, mock_check_output.call_count)
     first_call, second_call = mock_check_output.call_args_list
     self.assertEqual(
         mock.call(['juju', '--version'], stderr=subprocess.STDOUT),
         first_call,
     )
     self.assertEqual(mock.call(['juju', 'version']), second_call)
 def test_invalid_version(self, mock_check_output):
     # A ValueError is raised if the returned version is not valid.
     mock_check_output.return_value = '42'
     with self.assertRaises(ValueError) as info:
         juju_version()
     self.assertEqual("invalid juju version: '42'", str(info.exception))
 def test_all(self, mock_check_output):
     # Additional information is correctly handled.
     mock_check_output.side_effect = (self.error, 'juju 1.234-precise-i386')
     version = juju_version()
     self.assertEqual(Version(1, 234, 0), version)
     self.assertEqual(2, mock_check_output.call_count)
 def test_suffix(self, mock_check_output):
     # The function handles versions returned as "x.y.z-series-arch".
     mock_check_output.return_value = '1.10.3-raring-amd64'
     version = juju_version()
     self.assertEqual(Version(1, 10, 3), version)
 def test_prefix(self, mock_check_output):
     # The function handles versions returned as "juju x.y.z".
     mock_check_output.return_value = 'juju 0.8.3'
     version = juju_version()
     self.assertEqual(Version(0, 8, 3), version)
 def test_not_semantic_versioning(self, mock_check_output):
     # If the patch number is missing, it is set to zero.
     mock_check_output.return_value = '0.7'
     version = juju_version()
     self.assertEqual(Version(0, 7, 0), version)