Dre4m Shell
Server IP : 85.214.239.14  /  Your IP : 3.147.126.199
Web Server : Apache/2.4.62 (Debian)
System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64
User : www-data ( 33)
PHP Version : 7.4.18
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
MySQL : OFF  |  cURL : OFF  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : OFF
Directory :  /srv/modoboa/env/lib64/python3.5/site-packages/icalendar/tests/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME SHELL ]     

Current File : /srv/modoboa/env/lib64/python3.5/site-packages/icalendar/tests/test_unit_caselessdict.py
# -*- coding: utf-8 -*-
import unittest

import icalendar


class TestCaselessdict(unittest.TestCase):

    def test_caselessdict_canonsort_keys(self):
        canonsort_keys = icalendar.caselessdict.canonsort_keys

        keys = ['DTEND', 'DTSTAMP', 'DTSTART', 'UID', 'SUMMARY', 'LOCATION']

        out = canonsort_keys(keys)
        self.assertEqual(
            out,
            ['DTEND', 'DTSTAMP', 'DTSTART', 'LOCATION', 'SUMMARY', 'UID']
        )

        out = canonsort_keys(keys, ('SUMMARY', 'DTSTART', 'DTEND', ))
        self.assertEqual(
            out,
            ['SUMMARY', 'DTSTART', 'DTEND', 'DTSTAMP', 'LOCATION', 'UID']
        )

        out = canonsort_keys(keys, ('UID', 'DTSTART', 'DTEND', ))
        self.assertEqual(
            out,
            ['UID', 'DTSTART', 'DTEND', 'DTSTAMP', 'LOCATION', 'SUMMARY']
        )

        out = canonsort_keys(
            keys,
            ('UID', 'DTSTART', 'DTEND', 'RRULE', 'EXDATE')
        )
        self.assertEqual(
            out,
            ['UID', 'DTSTART', 'DTEND', 'DTSTAMP', 'LOCATION', 'SUMMARY']
        )

    def test_caselessdict_canonsort_items(self):
        canonsort_items = icalendar.caselessdict.canonsort_items

        d = {
            'i': 7, 'c': 'at', 'a': 3.5, 'l': (2, 3), 'e': [4, 5], 'n': 13, 'd': {'x': 'y'}, 'r': 1.0,
        }

        out = canonsort_items(d)
        self.assertEqual(
            out,
            [('a', 3.5), ('c', 'at'), ('d', {'x': 'y'}), ('e', [4, 5]),
             ('i', 7), ('l', (2, 3)), ('n', 13), ('r', 1.0)]
        )

        out = canonsort_items(d, ('i', 'c', 'a'))
        self.assertTrue(
            out,
            [('i', 7), ('c', 'at'), ('a', 3.5), ('d', {'x': 'y'}),
             ('e', [4, 5]), ('l', (2, 3)), ('n', 13), ('r', 1.0)]
        )

    def test_caselessdict_copy(self):
        CaselessDict = icalendar.caselessdict.CaselessDict

        original_dict = CaselessDict(key1='val1', key2='val2')
        copied_dict = original_dict.copy()

        self.assertEqual(original_dict, copied_dict)

    def test_CaselessDict(self):
        CaselessDict = icalendar.caselessdict.CaselessDict

        ncd = CaselessDict(key1='val1', key2='val2')
        self.assertEqual(
            ncd,
            CaselessDict({'KEY2': 'val2', 'KEY1': 'val1'})
        )

        self.assertEqual(ncd['key1'], 'val1')
        self.assertEqual(ncd['KEY1'], 'val1')

        ncd['KEY3'] = 'val3'
        self.assertEqual(ncd['key3'], 'val3')

        self.assertEqual(ncd.setdefault('key3', 'FOUND'), 'val3')
        self.assertEqual(ncd.setdefault('key4', 'NOT FOUND'), 'NOT FOUND')
        self.assertEqual(ncd['key4'], 'NOT FOUND')
        self.assertEqual(ncd.get('key1'), 'val1')
        self.assertEqual(ncd.get('key3', 'NOT FOUND'), 'val3')
        self.assertEqual(ncd.get('key4', 'NOT FOUND'), 'NOT FOUND')
        self.assertTrue('key4' in ncd)

        del ncd['key4']
        self.assertFalse('key4' in ncd)

        ncd.update({'key5': 'val5', 'KEY6': 'val6', 'KEY5': 'val7'})
        self.assertEqual(ncd['key6'], 'val6')

        keys = sorted(ncd.keys())
        self.assertEqual(keys, ['KEY1', 'KEY2', 'KEY3', 'KEY5', 'KEY6'])

Anon7 - 2022
AnonSec Team