Skip to main content
  • Home
  • login
  • Browse the archive

    swh mirror partner logo
swh logo
SoftwareHeritage
Software
Heritage
Mirror
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

Revision dbd56c149072e656ca8d6a43a59588f3e7513da2 authored by Hubert Kario on 29 September 2021, 13:05:34 UTC, committed by GitHub on 29 September 2021, 13:05:34 UTC
Merge pull request #777 from tlsfuzzer/descriptive-ExpectAlert
ExpectAlert - add __repr__
2 parent s 09d51ea + 34b0bc2
  • Files
  • Changes
  • dbc30ee
  • /
  • tests
  • /
  • test_tlsfuzzer_utils_ordered_dict.py
Raw File
Cook and download a directory from the Software Heritage Vault

You have requested the cooking of the directory with identifier None into a standard tar.gz archive.

Are you sure you want to continue ?

Download a directory from the Software Heritage Vault

You have requested the download of the directory with identifier None as a standard tar.gz archive.

Are you sure you want to continue ?

Cook and download a revision from the Software Heritage Vault

You have requested the cooking of the history heading to revision with identifier swh:1:rev:dbd56c149072e656ca8d6a43a59588f3e7513da2 into a bare git archive.

Are you sure you want to continue ?

Download a revision from the Software Heritage Vault

You have requested the download of the history heading to revision with identifier swh:1:rev:dbd56c149072e656ca8d6a43a59588f3e7513da2 as a bare git archive.

Are you sure you want to continue ?

Invalid Email !

The provided email is not well-formed.

Download link has expired

The requested archive is no longer available for download from the Software Heritage Vault.

Do you want to cook it again ?

Permalinks

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • revision
  • content
revision badge
swh:1:rev:dbd56c149072e656ca8d6a43a59588f3e7513da2
content badge Iframe embedding
swh:1:cnt:cc4c23c2c4b940d4b595135eb0e206c00d3b1563
test_tlsfuzzer_utils_ordered_dict.py
# Author: Hubert Kario, (c) 2017
# Released under Gnu GPL v2.0, see LICENSE file for details

try:
        import unittest2 as unittest
except ImportError:
        import unittest

from tlsfuzzer.utils.ordered_dict import OrderedDict

class TestOrderedDict(unittest.TestCase):
    def setUp(self):
        self.d = OrderedDict()
        self.d[1] = "a"
        self.d[2] = "b"
        self.d[3] = "c"

    def test___init__(self):
        d = OrderedDict()

        self.assertIsInstance(d, dict)

    def test___init___with_invalid_params(self):
        with self.assertRaises(TypeError):
            OrderedDict(12, "a")

    def test___init___with_dict(self):
        d = OrderedDict({12: "a", 14: "b"})

        self.assertEqual({12: "a", 14: "b"}, d)

    def test_add_in_order(self):
        d = OrderedDict()
        d[1] = "a"
        d[2] = "b"
        d[3] = "c"
        d[4] = "d"
        d[5] = "e"
        d[6] = "f"
        d[7] = "g"

        self.assertEqual([1, 2, 3, 4, 5, 6, 7], list(d.keys()))
        self.assertEqual(["a", "b", "c", "d", "e", "f", "g"], list(d.values()))

    def test_del(self):
        del self.d[2]

        self.assertEqual([1, 3], list(self.d.keys()))
        self.assertEqual(["a", "c"], list(self.d.values()))

    def test_iter(self):
        self.assertEqual([1, 2, 3], list(iter(self.d)))

    def test_popitem(self):
        n, v = self.d.popitem()

        self.assertEqual(n, 3)
        self.assertEqual(v, "c")
        self.assertEqual([1, 2], list(self.d.keys()))
        self.assertEqual(["a", "b"], list(self.d.values()))

    def test_popitem_on_empty(self):
        d = OrderedDict()

        with self.assertRaises(KeyError):
            d.popitem()

    def test_popitem_first(self):
        if type(self.d) is dict:
            self.skipTest("not popitem(last=False) in dict")
        else:
            n, v = self.d.popitem(last=False)

            self.assertEqual(n, 1)
            self.assertEqual(v, "a")
            self.assertEqual([2, 3], list(self.d.keys()))
            self.assertEqual(["b", "c"], list(self.d.values()))

    def test_items(self):
        self.assertEqual([(1, "a"), (2, "b"), (3, "c")], list(self.d.items()))

    def test_iterkeys(self):
        if type(self.d) is dict:
            self.skipTest("no iterkeys in dict")
        else:
            self.assertEqual(list(self.d.iterkeys()), list(iter(self.d)))

    def test_clear(self):
        self.d.clear()
        self.assertEqual([], list(self.d.items()))

    def test_itervalues(self):
        if type(self.d) is dict:
            self.skipTest("no itervalues in dict")
        else:
            self.assertEqual(list(self.d.itervalues()), self.d.values())

    def test_update_with_too_many_args(self):
        with self.assertRaises(TypeError):
            self.d.update(0, None)

    def test_update_with_dict(self):
        self.d.update({0: None})

        self.assertEqual([(1, "a"), (2, "b"), (3, "c"), (0, None)],
                         list(self.d.items()))

    def test_update_with_list_of_tuples(self):
        d = OrderedDict()
        d.update([(3, "c"), (2, "b"), (1, "a")])
        self.assertEqual([3, 2, 1], list(d.keys()))
        self.assertEqual(["c", "b", "a"], list(d.values()))

    def test_update_with_keyword_args(self):
        d = OrderedDict()
        d.update(a='1', b='2', c='3')
        self.assertEqual(set(['1', '2', '3']), set(d.values()))
        self.assertEqual(set(['a', 'b', 'c']), set(d.keys()))

    def test_pop(self):
        v = self.d.pop(2)
        self.assertEqual(v, "b")

        self.assertEqual([(1, "a"), (3, "c")], list(self.d.items()))

    def test_pop_non_existent(self):
        with self.assertRaises(KeyError):
            self.d.pop(4)

    def test_pop_with_default(self):
        if type(self.d) is dict:
            a = self.d.pop(0, "foo")
            self.assertEqual(a, "foo")
        else:
            a = self.d.pop(0, default="foo")
            self.assertEqual(a, "foo")

    def test_repr(self):
        if type(self.d) is dict:
            self.assertEqual("{1: 'a', 2: 'b', 3: 'c'}",
                             repr(self.d))
        else:
            self.assertEqual("OrderedDict([(1, 'a'), (2, 'b'), (3, 'c')])",
                             repr(self.d))

    def test_repr_with_circular_dependancy(self):
        del self.d[2]
        self.d[2] = self.d

        if type(self.d) is dict:
            self.assertEqual("{1: 'a', 3: 'c', 2: {...}}",
                             repr(self.d))
        else:
            self.assertEqual("OrderedDict([(1, 'a'), (3, 'c'), (2, ...)])",
                             repr(self.d))

    def test_repr_with_empty(self):
        d = OrderedDict()

        if type(self.d) is dict:
            self.assertEqual("{}", repr(d))
        else:
            self.assertEqual("OrderedDict()", repr(d))

    def test_compare_different_order(self):
        d2 = OrderedDict()
        d2[1] = "a"
        d2[3] = "c"
        d2[2] = "b"

        self.assertNotEqual(list(self.d.items()), list(d2.items()))
The diff you're trying to view is too large. Only the first 1000 changed files have been loaded.
Showing with 0 additions and 0 deletions (0 / 0 diffs computed)
swh spinner

Computing file changes ...

ENEA — Copyright (C), ENEA. License: GNU AGPLv3+.
Legal notes  ::  JavaScript license information ::  Web API

back to top