~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_config.py

  • Committer: Vincent Ladeuil
  • Date: 2009-05-05 15:31:34 UTC
  • mto: (4343.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 4344.
  • Revision ID: v.ladeuil+lp@free.fr-20090505153134-q4bp4is9gywsmzrv
Clean up test for log formats.

* bzrlib/tests/blackbox/test_logformats.py:
Update tests to actual style.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2008, 2009 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2008 Canonical Ltd
 
2
#   Authors: Robert Collins <robert.collins@canonical.com>
2
3
#
3
4
# This program is free software; you can redistribute it and/or modify
4
5
# it under the terms of the GNU General Public License as published by
17
18
"""Tests for finding and reading the bzr config file[s]."""
18
19
# import system imports here
19
20
from cStringIO import StringIO
 
21
import getpass
20
22
import os
21
23
import sys
22
24
 
366
368
        parser = my_config._get_parser(file=config_file)
367
369
        self.failUnless(my_config._get_parser() is parser)
368
370
 
369
 
    def test_get_user_option_as_bool(self):
370
 
        config_file = StringIO("""
371
 
a_true_bool = true
372
 
a_false_bool = 0
373
 
an_invalid_bool = maybe
374
 
a_list = hmm, who knows ? # This interpreted as a list !
375
 
""".encode('utf-8'))
376
 
        my_config = config.IniBasedConfig(None)
377
 
        parser = my_config._get_parser(file=config_file)
378
 
        get_option = my_config.get_user_option_as_bool
379
 
        self.assertEqual(True, get_option('a_true_bool'))
380
 
        self.assertEqual(False, get_option('a_false_bool'))
381
 
        self.assertIs(None, get_option('an_invalid_bool'))
382
 
        self.assertIs(None, get_option('not_defined_in_this_config'))
383
371
 
384
372
class TestGetConfig(tests.TestCase):
385
373
 
1473
1461
    """Test AuthenticationConfig behaviour"""
1474
1462
 
1475
1463
    def _check_default_password_prompt(self, expected_prompt_format, scheme,
1476
 
                                       host=None, port=None, realm=None,
1477
 
                                       path=None):
 
1464
                              host=None, port=None, realm=None, path=None):
1478
1465
        if host is None:
1479
1466
            host = 'bar.org'
1480
1467
        user, password = 'jim', 'precious'
1483
1470
            'user': user, 'realm': realm}
1484
1471
 
1485
1472
        stdout = tests.StringIOWrapper()
1486
 
        stderr = tests.StringIOWrapper()
1487
1473
        ui.ui_factory = tests.TestUIFactory(stdin=password + '\n',
1488
 
                                            stdout=stdout, stderr=stderr)
 
1474
                                            stdout=stdout)
1489
1475
        # We use an empty conf so that the user is always prompted
1490
1476
        conf = config.AuthenticationConfig()
1491
1477
        self.assertEquals(password,
1492
1478
                          conf.get_password(scheme, host, user, port=port,
1493
1479
                                            realm=realm, path=path))
1494
 
        self.assertEquals(expected_prompt, stderr.getvalue())
1495
 
        self.assertEquals('', stdout.getvalue())
 
1480
        self.assertEquals(stdout.getvalue(), expected_prompt)
1496
1481
 
1497
1482
    def _check_default_username_prompt(self, expected_prompt_format, scheme,
1498
 
                                       host=None, port=None, realm=None,
1499
 
                                       path=None):
 
1483
                              host=None, port=None, realm=None, path=None):
1500
1484
        if host is None:
1501
1485
            host = 'bar.org'
1502
1486
        username = 'jim'
1504
1488
            'scheme': scheme, 'host': host, 'port': port,
1505
1489
            'realm': realm}
1506
1490
        stdout = tests.StringIOWrapper()
1507
 
        stderr = tests.StringIOWrapper()
1508
1491
        ui.ui_factory = tests.TestUIFactory(stdin=username+ '\n',
1509
 
                                            stdout=stdout, stderr=stderr)
 
1492
                                            stdout=stdout)
1510
1493
        # We use an empty conf so that the user is always prompted
1511
1494
        conf = config.AuthenticationConfig()
1512
1495
        self.assertEquals(username, conf.get_user(scheme, host, port=port,
1513
1496
                          realm=realm, path=path, ask=True))
1514
 
        self.assertEquals(expected_prompt, stderr.getvalue())
1515
 
        self.assertEquals('', stdout.getvalue())
 
1497
        self.assertEquals(stdout.getvalue(), expected_prompt)
1516
1498
 
1517
1499
    def test_username_defaults_prompts(self):
1518
1500
        # HTTP prompts can't be tested here, see test_http.py
1560
1542
"""))
1561
1543
        entered_password = 'typed-by-hand'
1562
1544
        stdout = tests.StringIOWrapper()
1563
 
        stderr = tests.StringIOWrapper()
1564
1545
        ui.ui_factory = tests.TestUIFactory(stdin=entered_password + '\n',
1565
 
                                            stdout=stdout, stderr=stderr)
 
1546
                                            stdout=stdout)
1566
1547
 
1567
1548
        # Since the password defined in the authentication config is ignored,
1568
1549
        # the user is prompted
1582
1563
"""))
1583
1564
        entered_password = 'typed-by-hand'
1584
1565
        stdout = tests.StringIOWrapper()
1585
 
        stderr = tests.StringIOWrapper()
1586
1566
        ui.ui_factory = tests.TestUIFactory(stdin=entered_password + '\n',
1587
 
                                            stdout=stdout,
1588
 
                                            stderr=stderr)
 
1567
                                            stdout=stdout)
1589
1568
 
1590
1569
        # Since the password defined in the authentication config is ignored,
1591
1570
        # the user is prompted