Skip to content

Commit fb8b739

Browse files
author
Michael Barr
committed
Added all imports to the top of the file instead of within the test functions (Issue #4).
1 parent 5ee01a1 commit fb8b739

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

tests/test_core.py

+10-15
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
# =============================================================================
22
# >> IMPORTS
33
# =============================================================================
4+
# Python Imports
45
from unittest import TestCase, main
56

7+
# Settings Imports
8+
from steamwebapi.settings import STEAM_API_KEY, DEFAULT_LANGUAGE
9+
10+
# Core Imports
11+
from steamwebapi.core import SteamWebAPI, APIQuery
12+
13+
# Util Imports
14+
from steamwebapi.util.exceptions import APIKeyInvalidError
15+
616

717
# =============================================================================
818
# >> TEST CLASSES
@@ -12,7 +22,6 @@ class TestCoreSteamWebAPI(TestCase):
1222

1323
def setUp(self):
1424
"""Initializes a SteamWebAPI instance."""
15-
from steamwebapi.core import SteamWebAPI
1625
self.steamwebapi = SteamWebAPI()
1726

1827
# -------------------------------------------------------------------------
@@ -23,7 +32,6 @@ def test_api_key_equalto_settings_api_key(self):
2332
the STEAM_API_KEY from ./steamwebapi/settings.py.
2433
2534
"""
26-
from steamwebapi.settings import STEAM_API_KEY
2735
self.assertEqual(
2836
self.steamwebapi.key,
2937
STEAM_API_KEY,
@@ -37,7 +45,6 @@ def test_api_key_not_equalto_settings_api_key(self):
3745
STEAM_API_KEY from ./steamwebapi/settings.py.
3846
3947
"""
40-
from steamwebapi.settings import STEAM_API_KEY
4148
self.steamwebapi.key = 'XXXX0000XXXX0000XXXX0000XXXX0000'
4249
self.assertNotEqual(
4350
self.steamwebapi.key,
@@ -54,7 +61,6 @@ def test_api_key_initialized_from__init__with_keyword_arg(self):
5461
argument.
5562
5663
"""
57-
from steamwebapi.core import SteamWebAPI
5864
self.steamwebapi = SteamWebAPI(key='XXXX0000XXXX0000XXXX0000XXXX0000')
5965
self.assertEqual(
6066
self.steamwebapi.key,
@@ -69,7 +75,6 @@ def test_api_key_initialized_from__init__no_keyword_arg(self):
6975
causing a regression for users that do not provide keyword arguments.
7076
7177
"""
72-
from steamwebapi.core import SteamWebAPI
7378
# Set a fake (bad) Steam Web API Key
7479
self.steamwebapi = SteamWebAPI('XXXX0000XXXX0000XXXX0000XXXX0000')
7580
self.assertEqual(
@@ -85,8 +90,6 @@ def test_api_key_invalid_28_alphanumeric_characters(self):
8590
will test by passing in 28 alphanumeric characters.
8691
8792
"""
88-
from steamwebapi.core import SteamWebAPI
89-
from steamwebapi.util.exceptions import APIKeyInvalidError
9093
with self.assertRaises(APIKeyInvalidError):
9194
# Send a 28 instead of 32 character API key
9295
self.steamwebapi = SteamWebAPI('XXXX0000XXXX0000XXXX0000XXXX')
@@ -97,8 +100,6 @@ def test_api_key_invalid_non_alphanumeric_character(self):
97100
will test by passing in a non-alphanumeric character.
98101
99102
"""
100-
from steamwebapi.core import SteamWebAPI
101-
from steamwebapi.util.exceptions import APIKeyInvalidError
102103
with self.assertRaises(APIKeyInvalidError):
103104
# Add a "." (non-alphanumeric character)
104105
self.steamwebapi = SteamWebAPI('XXXX0000XXXX0000XXXX.000XXXX0000')
@@ -109,7 +110,6 @@ def test_api_key_empty(self):
109110
the APIKeyInvalidError.
110111
111112
"""
112-
from steamwebapi.core import SteamWebAPI
113113
self.steamwebapi = SteamWebAPI(key='')
114114
self.assertEqual(
115115
self.steamwebapi.key,
@@ -126,7 +126,6 @@ def test_default_language_equalto_settings_default_language(self):
126126
the DEFAULT_LANGUAGE from ./steamwebapi/settings.py.
127127
128128
"""
129-
from steamwebapi.settings import DEFAULT_LANGUAGE
130129
self.assertEqual(
131130
self.steamwebapi.language,
132131
DEFAULT_LANGUAGE,
@@ -140,7 +139,6 @@ def test_default_language_not_equalto_settings_default_language(self):
140139
DEFAULT_LANGUAGE from ./steamwebapi/settings.py.
141140
142141
"""
143-
from steamwebapi.settings import DEFAULT_LANGUAGE
144142
self.steamwebapi.language = 'not_a_real_language'
145143
self.assertNotEqual(
146144
self.steamwebapi.language,
@@ -157,7 +155,6 @@ def test_default_language_initialized_from__init__with_keyword_arg(self):
157155
name of the argument.
158156
159157
"""
160-
from steamwebapi.core import SteamWebAPI
161158
# Set a fake (bad) Steam Web API Key
162159
self.steamwebapi = SteamWebAPI(language='not_a_real_language')
163160
self.assertEqual(
@@ -174,7 +171,6 @@ def test_default_language_initialized_from__init__no_keyword_arg(self):
174171
keyword arguments.
175172
176173
"""
177-
from steamwebapi.core import SteamWebAPI
178174
# Set a fake (bad) Steam Web API Key
179175
self.steamwebapi = SteamWebAPI(
180176
'XXXX0000XXXX0000XXXX0000XXXX0000',
@@ -197,7 +193,6 @@ class TestAPIQuery(TestCase):
197193

198194
def setUp(self):
199195
"""Initializes an APIQuery instance."""
200-
from steamwebapi.core import APIQuery
201196
self.apiquery = APIQuery(
202197
interface='ISteamWebAPIUtil',
203198
method='GetSupportedAPIList',

0 commit comments

Comments
 (0)