summaryrefslogtreecommitdiffstats
path: root/awxkit/test
diff options
context:
space:
mode:
Diffstat (limited to 'awxkit/test')
-rw-r--r--awxkit/test/cli/test_client.py10
-rw-r--r--awxkit/test/cli/test_options.py5
-rw-r--r--awxkit/test/test_credentials.py5
-rw-r--r--awxkit/test/test_utils.py17
-rw-r--r--awxkit/test/test_ws.py5
5 files changed, 35 insertions, 7 deletions
diff --git a/awxkit/test/cli/test_client.py b/awxkit/test/cli/test_client.py
index db16e37393..e792b6c267 100644
--- a/awxkit/test/cli/test_client.py
+++ b/awxkit/test/cli/test_client.py
@@ -50,8 +50,14 @@ def test_list_resources(capfd, resource):
cli.parse_args(['awx {}'.format(resource)])
cli.connect()
- cli.parse_resource()
- out, err = capfd.readouterr()
+ try:
+ cli.parse_resource()
+ out, err = capfd.readouterr()
+ except SystemExit:
+ # python2 argparse raises SystemExit for invalid/missing required args,
+ # py3 doesn't
+ _, out = capfd.readouterr()
+
assert "usage:" in out
for snippet in (
'--conf.host https://example.awx.org]',
diff --git a/awxkit/test/cli/test_options.py b/awxkit/test/cli/test_options.py
index 3012349fd4..f0b22f1178 100644
--- a/awxkit/test/cli/test_options.py
+++ b/awxkit/test/cli/test_options.py
@@ -1,7 +1,10 @@
import argparse
import json
import unittest
-from io import StringIO
+try:
+ from StringIO import StringIO
+except ImportError:
+ from io import StringIO
import pytest
from requests import Response
diff --git a/awxkit/test/test_credentials.py b/awxkit/test/test_credentials.py
index 714550119e..bd1331016d 100644
--- a/awxkit/test/test_credentials.py
+++ b/awxkit/test/test_credentials.py
@@ -1,4 +1,7 @@
-from unittest.mock import patch
+try:
+ from unittest.mock import patch
+except ImportError:
+ from mock import patch
import pytest
diff --git a/awxkit/test/test_utils.py b/awxkit/test/test_utils.py
index df4081ccf9..20efa2c640 100644
--- a/awxkit/test/test_utils.py
+++ b/awxkit/test/test_utils.py
@@ -1,8 +1,13 @@
# -*- coding: utf-8 -*-
from datetime import datetime
+import sys
-from unittest import mock
+try:
+ from unittest import mock
+except ImportError:
+ import mock
import pytest
+import six
from awxkit import utils
from awxkit import exceptions as exc
@@ -73,11 +78,19 @@ def test_load_invalid_json_or_yaml(inp):
@pytest.mark.parametrize('non_ascii', [True, False])
+@pytest.mark.skipif(
+ sys.version_info < (3, 6),
+ reason='this is only intended to be used in py3, not the CLI'
+)
def test_random_titles_are_unicode(non_ascii):
- assert isinstance(utils.random_title(non_ascii=non_ascii), str)
+ assert isinstance(utils.random_title(non_ascii=non_ascii), six.text_type)
@pytest.mark.parametrize('non_ascii', [True, False])
+@pytest.mark.skipif(
+ sys.version_info < (3, 6),
+ reason='this is only intended to be used in py3, not the CLI'
+)
def test_random_titles_generates_correct_characters(non_ascii):
title = utils.random_title(non_ascii=non_ascii)
if non_ascii:
diff --git a/awxkit/test/test_ws.py b/awxkit/test/test_ws.py
index afc6b42fc5..ea55ba8ffa 100644
--- a/awxkit/test/test_ws.py
+++ b/awxkit/test/test_ws.py
@@ -1,7 +1,10 @@
# -*- coding: utf-8 -*-
from collections import namedtuple
-from unittest.mock import patch
+try:
+ from unittest.mock import patch
+except ImportError:
+ from mock import patch
import pytest
from awxkit.ws import WSClient