
import collections

import testtools

from sahara.utils import hashabledict as h


class HashableDictTest(testtools.TestCase):

    def test_is_hashable(self):
        hd = h.HashableDict()
        hd['one'] = 'oneValue'

        self.assertTrue(isinstance(hd, collections.Hashable))


import collections

import testtools

from sahara.utils import hashabledict as h


class HashableDictTest(testtools.TestCase):

    def test_is_hashable_collection(self):
        dct = h.HashableDict(one='oneValue')
        self.assertIsInstance(dct, collections.Hashable)

    def test_hash_consistency(self):
        dct1 = h.HashableDict(one='oneValue')
        dct2 = h.HashableDict(one='oneValue')
        self.assertEqual(hash(dct1), hash(dct2))

Improve unit test for HashableDict
Improve unit test for HashableDict

We have HashableDict introduced to network info storing, but hash
function of this implementation was never tested in unit tests.

Change-Id: Id48c9172ca63e19b397dc131d85ed631874142cd

  
  import collections
  
  import testtools
  
  from sahara.utils import hashabledict as h
  
  
  class HashableDictTest(testtools.TestCase):
  
-     def test_is_hashable(self):
+     def test_is_hashable_collection(self):
-         hd = h.HashableDict()
+         dct = h.HashableDict(one='oneValue')
-         hd['one'] = 'oneValue'
+         self.assertIsInstance(dct, collections.Hashable)
  
-         self.assertTrue(isinstance(hd, collections.Hashable))
+     def test_hash_consistency(self):
+         dct1 = h.HashableDict(one='oneValue')
+         dct2 = h.HashableDict(one='oneValue')
+         self.assertEqual(hash(dct1), hash(dct2))
  
Improve unit test for HashableDict
## Code Before:

import collections

import testtools

from sahara.utils import hashabledict as h


class HashableDictTest(testtools.TestCase):

    def test_is_hashable(self):
        hd = h.HashableDict()
        hd['one'] = 'oneValue'

        self.assertTrue(isinstance(hd, collections.Hashable))

## Instruction:
Improve unit test for HashableDict
## Code After:

import collections

import testtools

from sahara.utils import hashabledict as h


class HashableDictTest(testtools.TestCase):

    def test_is_hashable_collection(self):
        dct = h.HashableDict(one='oneValue')
        self.assertIsInstance(dct, collections.Hashable)

    def test_hash_consistency(self):
        dct1 = h.HashableDict(one='oneValue')
        dct2 = h.HashableDict(one='oneValue')
        self.assertEqual(hash(dct1), hash(dct2))
