<commit_before># -*- coding: utf-8 -*-

import icalendar
import pytz
import datetime
import os


import unittest
if not hasattr(unittest.TestCase, 'assertIsNotNone'):
    import unittest2 as unittest


class TestEncoding(unittest.TestCase):

    def test_create_from_ical(self):
        directory = os.path.dirname(__file__)
        data = open(os.path.join(directory, 'encoding.ics'), 'rb').read()
        cal = icalendar.Calendar.from_ical(data)

        self.assertEqual(cal['prodid'].to_ical(),
                         "-//Plönë.org//NONSGML plone.app.event//EN")
        self.assertEqual(cal['X-WR-CALDESC'].to_ical(),
                         "test non ascii: äöü ÄÖÜ €")

        event = cal.walk('VEVENT')[0]
        self.assertEqual(event['SUMMARY'].to_ical(),
                         'Non-ASCII Test: ÄÖÜ äöü €')
        self.assertEqual(event['DESCRIPTION'].to_ical(),
            'icalendar should be able to handle non-ascii: €äüöÄÜÖ.')
        self.assertEqual(event['LOCATION'].to_ical(),
                         'Tribstrül')

    def test_create_to_ical(self):
        cal = icalendar.Calendar()

        cal.add('prodid', u"-//Plönë.org//NONSGML plone.app.event//EN")
        cal.add('version', u"2.0")
        cal.add('x-wr-calname', u"äöü ÄÖÜ €")
        cal.add('x-wr-caldesc', u"test non ascii: äöü ÄÖÜ €")
        cal.add('x-wr-relcalid', u"12345")

        event = icalendar.Event()
        event.add('dtstart', datetime.datetime(2010, 10, 10, 10, 00, 00, tzinfo=pytz.utc))
        event.add('dtend', datetime.datetime(2010, 10, 10, 12, 00, 00, tzinfo=pytz.utc))
        event.add('created', datetime.datetime(2010, 10, 10, 0, 0, 0, tzinfo=pytz.utc))
        event.add('uid', u'123456')
        event.add('summary', u'Non-ASCII Test: ÄÖÜ äöü €')
        event.add('description', u'icalendar should be able to de/serialize non-ascii.')
        event.add('location', u'Tribstrül')
        cal.add_component(event)

        ical_lines = cal.to_ical().splitlines()
        cmp = 'PRODID:-//Pl\xc3\xb6n\xc3\xab.org//NONSGML plone.app.event//EN'
        self.assertTrue(cmp in ical_lines)

    def test_create_event_simple(self):
        event = icalendar.Event()
        event.add("dtstart", datetime.datetime(2010, 10, 10, 0, 0, 0, tzinfo=pytz.utc))
        event.add("summary", u"åäö")
        out = event.to_ical()
        summary = "SUMMARY:åäö"
        self.assertTrue(summary in out.splitlines())


    def test_unicode_parameter_name(self):
        # Test for issue #80
        cal = icalendar.Calendar()
        event = icalendar.Event()
        event.add(u'DESCRIPTION', u'äöüßÄÖÜ')
        cal.add_component(event)
        c = cal.to_ical()<commit_msg>test output for issuee #80. FIXES #80<commit_after># -*- coding: utf-8 -*-

import icalendar
import pytz
import datetime
import os


import unittest
if not hasattr(unittest.TestCase, 'assertIsNotNone'):
    import unittest2 as unittest


class TestEncoding(unittest.TestCase):

    def test_create_from_ical(self):
        directory = os.path.dirname(__file__)
        data = open(os.path.join(directory, 'encoding.ics'), 'rb').read()
        cal = icalendar.Calendar.from_ical(data)

        self.assertEqual(cal['prodid'].to_ical(),
                         "-//Plönë.org//NONSGML plone.app.event//EN")
        self.assertEqual(cal['X-WR-CALDESC'].to_ical(),
                         "test non ascii: äöü ÄÖÜ €")

        event = cal.walk('VEVENT')[0]
        self.assertEqual(event['SUMMARY'].to_ical(),
                         'Non-ASCII Test: ÄÖÜ äöü €')
        self.assertEqual(event['DESCRIPTION'].to_ical(),
            'icalendar should be able to handle non-ascii: €äüöÄÜÖ.')
        self.assertEqual(event['LOCATION'].to_ical(),
                         'Tribstrül')

    def test_create_to_ical(self):
        cal = icalendar.Calendar()

        cal.add('prodid', u"-//Plönë.org//NONSGML plone.app.event//EN")
        cal.add('version', u"2.0")
        cal.add('x-wr-calname', u"äöü ÄÖÜ €")
        cal.add('x-wr-caldesc', u"test non ascii: äöü ÄÖÜ €")
        cal.add('x-wr-relcalid', u"12345")

        event = icalendar.Event()
        event.add('dtstart', datetime.datetime(2010, 10, 10, 10, 00, 00, tzinfo=pytz.utc))
        event.add('dtend', datetime.datetime(2010, 10, 10, 12, 00, 00, tzinfo=pytz.utc))
        event.add('created', datetime.datetime(2010, 10, 10, 0, 0, 0, tzinfo=pytz.utc))
        event.add('uid', u'123456')
        event.add('summary', u'Non-ASCII Test: ÄÖÜ äöü €')
        event.add('description', u'icalendar should be able to de/serialize non-ascii.')
        event.add('location', u'Tribstrül')
        cal.add_component(event)

        ical_lines = cal.to_ical().splitlines()
        cmp = 'PRODID:-//Pl\xc3\xb6n\xc3\xab.org//NONSGML plone.app.event//EN'
        self.assertTrue(cmp in ical_lines)

    def test_create_event_simple(self):
        event = icalendar.Event()
        event.add("dtstart", datetime.datetime(2010, 10, 10, 0, 0, 0, tzinfo=pytz.utc))
        event.add("summary", u"åäö")
        out = event.to_ical()
        summary = "SUMMARY:åäö"
        self.assertTrue(summary in out.splitlines())


    def test_unicode_parameter_name(self):
        # Test for issue #80
        cal = icalendar.Calendar()
        event = icalendar.Event()
        event.add(u'DESCRIPTION', u'äöüßÄÖÜ')
        cal.add_component(event)
        c = cal.to_ical()
        self.assertEqual(c,
            'BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nDESCRIPTION:'\
            + '\xc3\xa4\xc3\xb6\xc3\xbc\xc3\x9f\xc3\x84\xc3\x96\xc3\x9c\r\n'\
            + 'END:VEVENT\r\nEND:VCALENDAR\r\n')
{'fraction_non_alphanumeric': 0.1551355206847361, 'fraction_numerical': 0.02870898716119829, 'mean_word_length': 2.4903546981953952, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '232371', 'n_tokens_mistral': 2116, 'n_tokens_neox': 1959, 'n_words': 355}