view test/test_mailer.py @ 7827:604da0650797

test: add basic tests using hypothesis It is segregated to its own file. I am skipping the entire file using importorskip(). Mixing hypothesis tests with non-hypothesis tests is tricky. Hypothesis uses decorators before test commands: @given(text()) @settings(max_examples=_max_examples) Pytest runs the decorators and the arguments as part of scanning the file for tests. This means the decorator (given, settings ...) and the strategies inside the decorators (e.g. text()) have to be defined using a lambda or something. Only aborting at the top of the file using importorskip prevents having to define all the symbols that would be imported from hypothesis.
author John Rouillard <rouilj@ieee.org>
date Sun, 24 Mar 2024 13:49:52 -0400
parents 95a366d46065
children
line wrap: on
line source

#-*- encoding: utf-8 -*-
import unittest

from roundup import mailer

class EncodingTestCase(unittest.TestCase):
    def testEncoding(self):
        a = lambda n, a, c, o: self.assertEqual(mailer.nice_sender_header(n,
            a, c), o)
        a('ascii', 'ascii@test.com', 'iso8859-1', 'ascii <ascii@test.com>')
        a(u'café', 'ascii@test.com', 'iso8859-1',
            '=?iso8859-1?q?caf=E9?= <ascii@test.com>')
        a(u'café', 'ascii@test.com', 'utf-8',
            '=?utf-8?b?Y2Fmw6k=?= <ascii@test.com>')
        a('as"ii', 'ascii@test.com', 'iso8859-1', '"as\\"ii" <ascii@test.com>')

# vim: set et sts=4 sw=4 :

Roundup Issue Tracker: http://roundup-tracker.org/