This repository has been archived by the owner on Apr 19, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Whoops, lost the case mapping tests there
- Loading branch information
Showing
1 changed file
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
"""Unit tests for IRC case mappings.""" | ||
# pylint: disable=missing-docstring,too-few-public-methods | ||
|
||
|
||
from twisted.trial.unittest import TestCase | ||
|
||
from ..case_mapping import (CaseMapping, CASE_MAPPINGS, | ||
case_mapping_by_name, CaseMappedDict) | ||
|
||
|
||
EXPECTED = { | ||
# Strings to compare # Equal under... | ||
('#foo', '#foo'): ('ascii', 'strict-rfc1459', 'rfc1459'), | ||
('#foo', '#FOO'): ('ascii', 'strict-rfc1459', 'rfc1459'), | ||
('#FOO', '#FOO'): ('ascii', 'strict-rfc1459', 'rfc1459'), | ||
('nick[tag]', 'nick{tag}'): ('strict-rfc1459', 'rfc1459'), | ||
('foo|bar', 'foo\\bar'): ('strict-rfc1459', 'rfc1459'), | ||
('hello~', 'hello^'): ('rfc1459'), | ||
('#foo', '#bar'): tuple() | ||
} | ||
|
||
|
||
class EqualityTester(object): | ||
def __init__(self, value): | ||
self.value = value | ||
|
||
def __eq__(self, other): | ||
return self.value | ||
|
||
def __ne__(self, other): | ||
return self.value | ||
|
||
|
||
class CaseMappingTestCase(TestCase): | ||
def test_hash(self): | ||
self.assertEqual(hash(CaseMapping('a', 'b')), | ||
hash(CaseMapping('a', 'b'))) | ||
self.assertNotEqual(hash(CaseMapping('a', 'b')), | ||
hash(CaseMapping('a', 'c'))) | ||
|
||
def test_equality(self): | ||
self.assertEqual(CaseMapping('a', 'b'), CaseMapping('a', 'b')) | ||
self.assertNotEqual(CaseMapping('a', 'b'), CaseMapping('a', 'c')) | ||
self.assertTrue(CaseMapping('a', 'b') == EqualityTester(True)) | ||
self.assertFalse(CaseMapping('a', 'b') == EqualityTester(False)) | ||
self.assertTrue(CaseMapping('a', 'b') != EqualityTester(True)) | ||
self.assertFalse(CaseMapping('a', 'b') != EqualityTester(False)) | ||
|
||
def test_equates(self): | ||
for (a, b), equal_case_mappings in EXPECTED.iteritems(): | ||
for name in CASE_MAPPINGS: | ||
case_mapping = case_mapping_by_name(name) | ||
self.assertIs(case_mapping.equates(a, b), | ||
name in equal_case_mappings) | ||
|
||
def test_upper_equates(self): | ||
for (a, b), equal_case_mappings in EXPECTED.iteritems(): | ||
for name in CASE_MAPPINGS: | ||
case_mapping = case_mapping_by_name(name) | ||
self.assertIs( | ||
case_mapping.upper(a) == case_mapping.upper(b), | ||
name in equal_case_mappings) | ||
|
||
def test_unrecognized_name(self): | ||
self.assertRaises(ValueError, case_mapping_by_name, 'spam') | ||
|
||
|
||
class CaseMappedDictTestCase(TestCase): | ||
def test_no_mapping(self): | ||
self.assertIs(CaseMappedDict().case_mapping, CASE_MAPPINGS['rfc1459']) | ||
|
||
def test_lookup(self): | ||
for (a, b), equal_case_mappings in EXPECTED.iteritems(): | ||
for name in CASE_MAPPINGS: | ||
d = CaseMappedDict(case_mapping=name) | ||
d[a] = 1 | ||
if name in equal_case_mappings: | ||
self.assertEqual(d.get(b), 1) | ||
else: | ||
self.assertIsNone(d.get(b)) | ||
|
||
def test_nonstring_keys(self): | ||
d = CaseMappedDict() | ||
d[9001] = 1 | ||
self.assertEqual(d[9001], 1) |