~gz/brz/knit_load_py3

« back to all changes in this revision

Viewing changes to breezy/tests/test_config.py

  • Committer: Jelmer Vernooij
  • Date: 2018-06-17 11:15:04 UTC
  • mto: (6973.12.2 python3-k)
  • mto: This revision was merged to the branch mainline in revision 7003.
  • Revision ID: jelmer@jelmer.uk-20180617111504-i2eqvqbtfj5bp0t3
s/file/open.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2592
2592
    loaded. We need to issue proper error messages in this case.
2593
2593
    """
2594
2594
 
2595
 
    invalid_utf8_char = '\xff'
 
2595
    invalid_utf8_char = b'\xff'
2596
2596
 
2597
2597
    def test_load_utf8(self):
2598
2598
        """Ensure we can load an utf8-encoded file."""
2609
2609
    def test_load_badly_encoded_content(self):
2610
2610
        """Ensure we display a proper error on non-ascii, non utf-8 content."""
2611
2611
        with open('foo.conf', 'wb') as f:
2612
 
            f.write('user=foo\n#%s\n' % (self.invalid_utf8_char,))
 
2612
            f.write(b'user=foo\n#%s\n' % (self.invalid_utf8_char,))
2613
2613
        conf = config.IniBasedConfig(file_name='foo.conf')
2614
2614
        self.assertRaises(config.ConfigContentError, conf._get_parser)
2615
2615
 
2616
2616
    def test_load_erroneous_content(self):
2617
2617
        """Ensure we display a proper error on content that can't be parsed."""
2618
2618
        with open('foo.conf', 'wb') as f:
2619
 
            f.write('[open_section\n')
 
2619
            f.write(b'[open_section\n')
2620
2620
        conf = config.IniBasedConfig(file_name='foo.conf')
2621
2621
        self.assertRaises(config.ParseConfigError, conf._get_parser)
2622
2622
 
4700
4700
    """Test retrieving default domain from mailname file"""
4701
4701
 
4702
4702
    def test_default_mail_domain_simple(self):
4703
 
        f = file('simple', 'w')
4704
 
        try:
 
4703
        with open('simple', 'w') as f:
4705
4704
            f.write("domainname.com\n")
4706
 
        finally:
4707
 
            f.close()
4708
4705
        r = config._get_default_mail_domain('simple')
4709
4706
        self.assertEqual('domainname.com', r)
4710
4707
 
4711
4708
    def test_default_mail_domain_no_eol(self):
4712
 
        f = file('no_eol', 'w')
4713
 
        try:
 
4709
        with open('no_eol', 'w') as f:
4714
4710
            f.write("domainname.com")
4715
 
        finally:
4716
 
            f.close()
4717
4711
        r = config._get_default_mail_domain('no_eol')
4718
4712
        self.assertEqual('domainname.com', r)
4719
4713
 
4720
4714
    def test_default_mail_domain_multiple_lines(self):
4721
 
        f = file('multiple_lines', 'w')
4722
 
        try:
 
4715
        with open('multiple_lines', 'w') as f:
4723
4716
            f.write("domainname.com\nsome other text\n")
4724
 
        finally:
4725
 
            f.close()
4726
4717
        r = config._get_default_mail_domain('multiple_lines')
4727
4718
        self.assertEqual('domainname.com', r)
4728
4719