def test_check_proper_gcloud(self, test_patch): """Test check_proper_gcloud() works with proper version/alpha.""" test_patch.return_value = (0, 'Google Cloud SDK %s\nalpha 12345\netc' % self.gcloud_min_ver_formatted, None) output_head = 'Current gcloud version' with captured_output() as (out, err): gcloud.check_proper_gcloud() output = out.getvalue()[:len(output_head)] self.assertEqual(output_head, output)
def test_gcloud_info_cmd_fails(self, test_patch): """Test gcloud_info() exits when command fails.""" test_patch.return_value = ( 1, None, 'Error output' ) with self.assertRaises(SystemExit): with captured_output(): gcloud.check_proper_gcloud()
def test_check_proper_gcloud_failed_command(self, test_patch): """Test check_proper_gcloud() exits when command fails.""" test_patch.return_value = (1, 'Google Cloud SDK %s\nalpha 12345\netc' % self.gcloud_min_ver_formatted, None) output_head = 'Error' with self.assertRaises(SystemExit): with captured_output() as (out, err): gcloud.check_proper_gcloud() output = out.getvalue()[:len(output_head)] self.assertEqual(output_head, output)
def test_check_proper_gcloud_low_version(self, test_patch): """Test check_proper_gcloud() exits with low gcloud version.""" test_patch.return_value = ( 0, 'Google Cloud SDK 162.9.9\nalpha 12345\netc', None) output_head = ('Current gcloud version: %s\n' 'Has alpha components? True' 'You need' % self.gcloud_min_ver_formatted) with self.assertRaises(SystemExit): with captured_output() as (out, err): gcloud.check_proper_gcloud() output = out.getvalue()[:len(output_head)]
def test_check_proper_gcloud_no_alpha(self, test_patch): """Test check_proper_gcloud() exits with no alpha components.""" test_patch.return_value = (0, 'Google Cloud SDK %s\netc' % self.gcloud_min_ver_formatted, None) output_head = ('Current gcloud version: %s\n' 'Has alpha components? False\n' 'You need' % self.gcloud_min_ver_formatted) with self.assertRaises(SystemExit): with captured_output() as (out, err): gcloud.check_proper_gcloud() output = out.getvalue()[:len(output_head)] self.assertEqual(output_head, output)