Exemplo n.º 1
0
    def test_vanity_version_downloads(self, mock_json_func, mock_norm_func):
        # NB: mocks are passed in reverse order
        expected_url = 'https://pypi.python.org/pypi/fake-package/json'

        vanity.vanity(packages=['fake-package==1.0'],
                      verbose=True,
                      json=True,
                      pattern=None)

        mock_norm_func.assert_called_with('fake-package')
        mock_json_func.assert_called_with(expected_url)
        self.mock_logger.debug.assert_any_call(
            '%s %s has been downloaded %s times!', 'fake-package', '1.0', '6')
Exemplo n.º 2
0
    def test_vanity_count_downloads(self, mock_json_func, mock_norm_func):
        # NB: mocks are passed in reverse order
        expected_url = 'https://pypi.python.org/pypi/fake-package/json'

        vanity.vanity(packages=['fake-package'],
                      verbose=True,
                      json=True,
                      pattern=None)

        mock_norm_func.assert_called_with('fake-package')
        mock_json_func.assert_called_with(expected_url)
        self.mock_logger.debug.assert_any_call(
            '%s has been downloaded %s times!',
            'fake-package',
            '6')
Exemplo n.º 3
0
#
# use vanity to get cumulative download count for each version
#

# temporarily redirect stdout and argv before calling vanity
stream = cStringIO.StringIO()
stdout_ = sys.stdout
sys.stdout = stream
argv_ = sys.argv
sys.argv = ['vanity', pypi_pkg]

count = 1
while count <= 5:
    try:
        sys.stderr.write('vanity try %d ...\n' % (count))
        vanity.vanity()
        break
    except Exception as e:
        sys.stderr.write(str(e)+'\n')
        count = count + 1
        continue

# restore stdout and stdout
sys.argv = argv_
sys.stdout = stdout_

doc = stream.getvalue()
downloads = re.split('\n', doc)
#print downloads

data = {'Date':date.today(), 'Timestamp':datetime.utcnow()}