1 """Tests for distutils.pypirc.pypirc."""
8 from distutils
.core
import PyPIRCCommand
9 from distutils
.core
import Distribution
10 from distutils
.log
import set_threshold
11 from distutils
.log
import WARN
13 from distutils
.tests
import support
30 repository:http://another.pypi/
50 class PyPIRCCommandTestCase(support
.TempdirManager
,
51 support
.LoggingSilencer
,
56 """Patches the environment."""
57 super(PyPIRCCommandTestCase
, self
).setUp()
58 self
.tmp_dir
= self
.mkdtemp()
59 os
.environ
['HOME'] = self
.tmp_dir
60 self
.rc
= os
.path
.join(self
.tmp_dir
, '.pypirc')
61 self
.dist
= Distribution()
63 class command(PyPIRCCommand
):
64 def __init__(self
, dist
):
65 PyPIRCCommand
.__init
__(self
, dist
)
66 def initialize_options(self
):
68 finalize_options
= initialize_options
71 self
.old_threshold
= set_threshold(WARN
)
74 """Removes the patch."""
75 set_threshold(self
.old_threshold
)
76 super(PyPIRCCommandTestCase
, self
).tearDown()
78 def test_server_registration(self
):
79 # This test makes sure PyPIRCCommand knows how to:
80 # 1. handle several sections in .pypirc
81 # 2. handle the old format
84 self
.write_file(self
.rc
, PYPIRC
)
85 cmd
= self
._cmd
(self
.dist
)
86 config
= cmd
._read
_pypirc
()
88 config
= config
.items()
90 waited
= [('password', 'secret'), ('realm', 'pypi'),
91 ('repository', 'http://pypi.python.org/pypi'),
92 ('server', 'server1'), ('username', 'me')]
93 self
.assertEquals(config
, waited
)
96 self
.write_file(self
.rc
, PYPIRC_OLD
)
97 config
= cmd
._read
_pypirc
()
98 config
= config
.items()
100 waited
= [('password', 'secret'), ('realm', 'pypi'),
101 ('repository', 'http://pypi.python.org/pypi'),
102 ('server', 'server-login'), ('username', 'tarek')]
103 self
.assertEquals(config
, waited
)
105 def test_server_empty_registration(self
):
106 cmd
= self
._cmd
(self
.dist
)
107 rc
= cmd
._get
_rc
_file
()
108 self
.assertTrue(not os
.path
.exists(rc
))
109 cmd
._store
_pypirc
('tarek', 'xxx')
110 self
.assertTrue(os
.path
.exists(rc
))
111 content
= open(rc
).read()
112 self
.assertEquals(content
, WANTED
)
115 return unittest
.makeSuite(PyPIRCCommandTestCase
)
117 if __name__
== "__main__":
118 unittest
.main(defaultTest
="test_suite")