Ejemplo n.º 1
0
    def test_init(self):
        m_pip_logger = Mock()
        m_pip_s_logger = Mock()

        def se_get_logger(lname):
            if lname == 'pip':
                return m_pip_logger
            if lname == 'pip.subprocessor':
                return m_pip_s_logger

        with patch('%s.inspect.stack' % pbm, autospec=True) as m_stack:
            with patch('%s.logger' % pbm, autospec=True) as m_logger:
                with patch('%s.logging.getLogger' % pbm,
                           autospec=True) as m_get_log:
                    m_get_log.side_effect = se_get_logger
                    cls = VersionFinder('foobar',
                                        package_file='/foo/bar/baz.py')
        assert m_stack.mock_calls == []
        assert cls.package_name == 'foobar'
        assert cls.package_file == '/foo/bar/baz.py'
        assert cls.package_dir == '/foo/bar'
        assert m_logger.mock_calls == [
            call.setLevel(logging.CRITICAL),
            call.debug('Finding package version for: %s', 'foobar'),
            call.debug('Explicit package file: %s', '/foo/bar/baz.py'),
            call.debug('package_dir: /foo/bar')
        ]
        assert m_get_log.mock_calls == [call('pip'), call('pip.subprocessor')]
        assert m_pip_logger.mock_calls == [call.setLevel(logging.CRITICAL)]
        assert m_pip_s_logger.mock_calls == []
Ejemplo n.º 2
0
 def test_init_no_file(self):
     m_frame = Mock()
     type(m_frame).filename = '/tmp/foo.py'
     m_stack_frame = Mock()
     with patch('%s.inspect.stack' % pbm, autospec=True) as m_stack:
         with patch('%s.inspect.getframeinfo' % pbm) as m_get_frame:
             m_stack.return_value = [None, []]
             m_get_frame.return_value = m_frame
             cls = VersionFinder('foobar', caller_frame=m_stack_frame)
     assert m_stack.mock_calls == []
     assert m_get_frame.mock_calls == [call(m_stack_frame)]
     assert cls.package_name == 'foobar'
     assert cls.package_file == '/tmp/foo.py'
     assert cls.package_dir == '/tmp'
Ejemplo n.º 3
0
 def test_init(self):
     m_pip_logger = Mock()
     with patch('%s.inspect.stack' % pbm, autospec=True) as m_stack:
         with patch('%s.logger' % pbm, autospec=True) as m_logger:
             with patch('%s.logging.getLogger' % pbm,
                        autospec=True) as m_log_pip:
                 m_log_pip.return_value = m_pip_logger
                 cls = VersionFinder('foobar',
                                     package_file='/foo/bar/baz.py')
     assert m_stack.mock_calls == []
     assert cls.package_name == 'foobar'
     assert cls.package_file == '/foo/bar/baz.py'
     assert cls.package_dir == '/foo/bar'
     assert m_logger.mock_calls == [
         call.setLevel(logging.CRITICAL),
         call.debug('Finding package version for: %s', 'foobar'),
         call.debug('Explicit package file: %s', '/foo/bar/baz.py'),
         call.debug('package_dir: /foo/bar')
     ]
     assert m_log_pip.mock_calls == [call('pip')]
     assert m_pip_logger.mock_calls == [call.setLevel(logging.CRITICAL)]
Ejemplo n.º 4
0
 def setup_method(self, _):
     self.cls = VersionFinder('foo', package_file='/foo/bar/baz.py')