# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
# Copyright 2017 Anaconda, Inc.
#
# All Rights Reserved.
# -----------------------------------------------------------------------------
import os.path

import pytest

from anaconda_enterprise.cli import parse
from .base import FIXTURES

WHL = 'Flask-1.0.2-py2.py3-none-any.whl'
SDIST = 'Flask-1.0.2.tar.gz'


@pytest.mark.parametrize(['filename'], [
    (WHL, ),
    (SDIST, ),
])
def test_parse_pypi(filename):
    path = os.path.join(FIXTURES, filename)
    attrs = parse.parse_pypi(path)

    assert attrs['filename'] == filename
    assert attrs['version'] == '1.0.2'
    assert attrs['about-attributes']['license_family'] == 'BSD'
    assert attrs['index-attributes']['name'] == 'Flask'
    assert 'License :: OSI Approved :: BSD License' in attrs['pkg-info']['classifier']
    assert {'click', 'itsdangerous', 'Jinja2', 'Werkzeug'
            } == {req['name']
                  for req in attrs['requirements']}
    assert {
        'pytest', 'coverage', 'tox', 'sphinx', 'pallets-sphinx-themes', 'sphinxcontrib-log-cabinet'
    } == {req['name']
          for req in attrs['extra-requirements']['dev']}


@pytest.mark.parametrize(['filename', 'name', 'version'], [
    ('ipython-0.12.1.win-amd64.exe', 'ipython', '0.12.1'),
    ('simplejson-3.15.0.win-amd64-py2.7.exe', 'simplejson', '3.15.0'),
    ('simplejson-3.15.0.win32-py2.7.exe', 'simplejson', '3.15.0'),
    ('simple.json-3.15.0.win-amd64-py2.7.exe', 'simple.json', '3.15.0'),
    ('simple-json-3.15.0.win32-py2.7.exe', 'simple-json', '3.15.0'),
    ('simplejson-3.15.0-10.win32-py2.7.exe', 'simplejson', '3.15.0-10'),
    ('simple.json-3.15.0-10.win32-py2.7.exe', 'simple.json', '3.15.0-10'),
    ('simple-json-3.15.0-10.win32-py2.7.exe', 'simple-json', '3.15.0-10'),
])
def test_parse_pypi_exe(filename, name, version):
    attrs = parse.parse_pypi_exe(filename)

    assert attrs['index-attributes']['name'] == name
    assert attrs['version'] == version
