Browse Source

fixed correctly recognizing str in SteamID init

pull/18/merge
Rossen Georgiev 9 years ago
parent
commit
83f7a35940
  1. 4
      steam/steamid.py
  2. 13
      tests/test_steamid.py

4
steam/steamid.py

@ -84,13 +84,13 @@ class SteamID(object):
if type(value) in (int, EType): if type(value) in (int, EType):
self.type = EType(value) self.type = EType(value)
else: else:
self.type = EType[value.lower().capitalize()] self.type = EType[value]
value = kwargs.get('universe', 1) value = kwargs.get('universe', 1)
if type(value) in (int, EUniverse): if type(value) in (int, EUniverse):
self.universe = EUniverse(value) self.universe = EUniverse(value)
else: else:
self.universe = EUniverse[value.lower().capitalize()] self.universe = EUniverse[value]
if 'instance' in kwargs: if 'instance' in kwargs:
self.instance = kwargs['instance'] self.instance = kwargs['instance']

13
tests/test_steamid.py

@ -135,24 +135,24 @@ class SteamID_initialization(unittest.TestCase):
SteamID(id=5, type="doesn't exist") SteamID(id=5, type="doesn't exist")
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
SteamID(id=5, type=99999999) SteamID(id=5, type=99999999)
with self.assertRaises(AttributeError): with self.assertRaises(KeyError):
SteamID(id=5, type=None) SteamID(id=5, type=None)
self.assertEqual(SteamID(id=5, type=1).type, EType.Individual) self.assertEqual(SteamID(id=5, type=1).type, EType.Individual)
self.assertEqual(SteamID(id=5, type='Individual').type, EType.Individual) self.assertEqual(SteamID(id=5, type='Individual').type, EType.Individual)
self.assertEqual(SteamID(id=5, type='iNDIVIDUAL').type, EType.Individual) self.assertEqual(SteamID(id=5, type='AnonUser').type, EType.AnonUser)
def test_kwarg_universe(self): def test_kwarg_universe(self):
with self.assertRaises(KeyError): with self.assertRaises(KeyError):
SteamID(id=5, universe="doesn't exist") SteamID(id=5, universe="doesn't exist")
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
SteamID(id=5, universe=99999999) SteamID(id=5, universe=99999999)
with self.assertRaises(AttributeError): with self.assertRaises(KeyError):
SteamID(id=5, universe=None) SteamID(id=5, universe=None)
self.assertEqual(SteamID(id=5, universe=1).universe, EUniverse.Public) self.assertEqual(SteamID(id=5, universe=1).universe, EUniverse.Public)
self.assertEqual(SteamID(id=5, universe='Public').universe, EUniverse.Public) self.assertEqual(SteamID(id=5, universe='Public').universe, EUniverse.Public)
self.assertEqual(SteamID(id=5, universe='pUBLIC').universe, EUniverse.Public) self.assertEqual(SteamID(id=5, universe='Dev').universe, EUniverse.Dev)
def test_kwarg_instance(self): def test_kwarg_instance(self):
self.assertEqual(SteamID(id=5, instance=1234).instance, 1234) self.assertEqual(SteamID(id=5, instance=1234).instance, 1234)
@ -176,11 +176,6 @@ class SteamID_initialization(unittest.TestCase):
universe='Invalid', universe='Invalid',
instance=0, instance=0,
), invalid) ), invalid)
self.compare(SteamID(id=0,
type='iNVALID',
universe='iNVALID',
instance=0,
), invalid)
class SteamID_properties(unittest.TestCase): class SteamID_properties(unittest.TestCase):

Loading…
Cancel
Save