コード例 #1
0
def test_local_specifier():
  for ext in ('.tar.gz', '.tar', '.tgz', '.zip', '.tar.bz2'):
    sl = SourcePackage('a_p_r-3.1.3+pexed.1' + ext)
    assert sl.name == 'a-p-r'
    assert sl.raw_version == '3.1.3+pexed.1'
    assert sl.version == parse_version(sl.raw_version)
    assert sl.satisfies('a_p_r==3.1.3+pexed.1')
コード例 #2
0
ファイル: test_package.py プロジェクト: butlern/pex
def test_local_specifier():
    for ext in ('.tar.gz', '.tar', '.tgz', '.zip', '.tar.bz2'):
        sl = SourcePackage('a_p_r-3.1.3+pexed.1' + ext)
        assert sl.name == 'a-p-r'
        assert sl.raw_version == '3.1.3+pexed.1'
        assert sl.version == parse_version(sl.raw_version)
        assert sl.satisfies('a_p_r==3.1.3+pexed.1')
コード例 #3
0
ファイル: test_package.py プロジェクト: kamilchm/pex
def test_package_fetch_without_location():
  with temporary_dir() as td:
    dateutil_base = 'python-dateutil-1.5'
    dateutil = '%s.zip' % dateutil_base
    with contextlib.closing(ZipFile(os.path.join(td, dateutil), 'w')) as zf:
      zf.writestr(os.path.join(dateutil_base, 'file1.txt'), 'junk1')
      zf.writestr(os.path.join(dateutil_base, 'file2.txt'), 'junk2')

    sl = SourcePackage('file://' + os.path.join(td, dateutil), opener=Web())
    dest = sl.fetch()

    assert set(os.listdir(dest)) == set(['file1.txt', 'file2.txt'])
コード例 #4
0
ファイル: test_package.py プロジェクト: kamilchm/pex
def test_source_packages():
  for ext in ('.tar.gz', '.tar', '.tgz', '.zip', '.tar.bz2'):
    sl = SourcePackage('a_p_r-3.1.3' + ext)
    assert sl._name == 'a_p_r'
    assert sl.name == 'a-p-r'
    assert sl.raw_version == '3.1.3'
    assert sl.version == parse_version(sl.raw_version)
    for req in ('a_p_r', 'a_p_r>2', 'a_p_r>3', 'a_p_r>=3.1.3', 'a_p_r==3.1.3', 'a_p_r>3,<3.5'):
      assert sl.satisfies(req)
      assert sl.satisfies(Requirement.parse(req))
    for req in ('foo', 'a_p_r==4.0.0', 'a_p_r>4.0.0', 'a_p_r>3.0.0,<3.0.3', 'a==3.1.3'):
      assert not sl.satisfies(req)
  sl = SourcePackage('python-dateutil-1.5.tar.gz')
  assert sl.name == 'python-dateutil'
  assert sl.raw_version == '1.5'

  with temporary_dir() as td:
    dateutil_base = 'python-dateutil-1.5'
    dateutil = '%s.zip' % dateutil_base
    with contextlib.closing(ZipFile(os.path.join(td, dateutil), 'w')) as zf:
      zf.writestr(os.path.join(dateutil_base, 'file1.txt'), 'junk1')
      zf.writestr(os.path.join(dateutil_base, 'file2.txt'), 'junk2')
    sl = SourcePackage('file://' + os.path.join(td, dateutil), opener=Web())
    with temporary_dir() as td2:
      sl.fetch(location=td2)
      print(os.listdir(td2))
      assert set(os.listdir(os.path.join(td2, dateutil_base))) == set(['file1.txt', 'file2.txt'])
コード例 #5
0
def test_source_packages():
  for ext in ('.tar.gz', '.tar', '.tgz', '.zip', '.tar.bz2'):
    sl = SourcePackage('a_p_r-3.1.3' + ext)
    assert sl._name == 'a_p_r'
    assert sl.name == 'a-p-r'
    assert sl.raw_version == '3.1.3'
    assert sl.version == parse_version(sl.raw_version)
    for req in ('a_p_r', 'a_p_r>2', 'a_p_r>3', 'a_p_r>=3.1.3', 'a_p_r==3.1.3', 'a_p_r>3,<3.5'):
      assert sl.satisfies(req)
      assert sl.satisfies(Requirement.parse(req))
    for req in ('foo', 'a_p_r==4.0.0', 'a_p_r>4.0.0', 'a_p_r>3.0.0,<3.0.3', 'a==3.1.3'):
      assert not sl.satisfies(req)
  sl = SourcePackage('python-dateutil-1.5.tar.gz')
  assert sl.name == 'python-dateutil'
  assert sl.raw_version == '1.5'
コード例 #6
0
def test_resolvable_requirement():
    req = 'foo[bar]==2.3.4'
    resolvable = ResolvableRequirement.from_string(
        req, ResolverOptionsBuilder(fetchers=[]))
    assert resolvable.requirement == pkg_resources.Requirement.parse(
        'foo[bar]==2.3.4')
    assert resolvable.name == 'foo'
    assert resolvable.exact is True
    assert resolvable.extras() == ['bar']
    assert resolvable.options._fetchers == []
    assert resolvable.packages() == []

    source_pkg = SourcePackage.from_href('foo-2.3.4.tar.gz')
    mock_iterator = mock.create_autospec(Iterator, spec_set=True)
    mock_iterator.iter.return_value = iter([source_pkg])
    assert resolvable.compatible(mock_iterator) == [source_pkg]
    assert mock_iterator.iter.mock_calls == [
        mock.call(pkg_resources.Requirement.parse('foo[bar]==2.3.4'))
    ]

    # test non-exact
    resolvable = ResolvableRequirement.from_string('foo',
                                                   ResolverOptionsBuilder())
    assert resolvable.exact is False

    # test Resolvable.get, which should delegate to a ResolvableRequirement in this case
    assert Resolvable.get('foo') == ResolvableRequirement.from_string(
        'foo', ResolverOptionsBuilder())
コード例 #7
0
def test_resolvable_package():
    builder = ResolverOptionsBuilder()
    source_name = 'foo-2.3.4.tar.gz'
    pkg = SourcePackage.from_href(source_name)
    resolvable = ResolvablePackage.from_string(source_name, builder)
    assert resolvable.packages() == [pkg]

    mock_iterator = mock.create_autospec(Iterator, spec_set=True)
    mock_iterator.iter.return_value = iter([])
    # fetchers are currently unused for static packages.
    assert resolvable.compatible(mock_iterator) == []
    assert mock_iterator.iter.mock_calls == []
    assert resolvable.name == 'foo'
    assert resolvable.exact is True
    assert resolvable.extras() == []

    resolvable = ResolvablePackage.from_string(source_name + '[extra1,extra2]',
                                               builder)
    assert resolvable.extras() == ['extra1', 'extra2']

    assert Resolvable.get('foo-2.3.4.tar.gz') == ResolvablePackage.from_string(
        'foo-2.3.4.tar.gz', builder)

    with pytest.raises(ResolvablePackage.InvalidRequirement):
        ResolvablePackage.from_string('foo', builder)
コード例 #8
0
def test_resolvable_set_is_constraint_only():
  builder = ResolverOptionsBuilder()
  rs = _ResolvableSet()
  c = ResolvableRequirement.from_string('foo', builder)
  c.is_constraint = True

  package = SourcePackage.from_href('foo-2.3.4.tar.gz')
  rs.merge(c, [package])

  assert rs.packages() == [(c, set([package]), None, True)]
コード例 #9
0
ファイル: test_resolver.py プロジェクト: pfmoore/pex
def test_resolvable_set_is_constraint_only():
  builder = ResolverOptionsBuilder()
  rs = _ResolvableSet()
  c = ResolvableRequirement.from_string('foo', builder)
  c.is_constraint = True

  package = SourcePackage.from_href('foo-2.3.4.tar.gz')
  rs.merge(c, [package])

  assert rs.packages() == [(c, set([package]), None, True)]
コード例 #10
0
ファイル: test_iterator.py プロジェクト: yolken/pex
def test_iteration_with_return():
    pex_url = 'https://pypi.python.org/packages/source/p/pex/pex-0.8.6.tar.gz'
    crawler_mock = mock.create_autospec(Crawler, spec_set=True)
    crawler_mock.crawl.return_value = [pex_url]
    iterator = Iterator(crawler=crawler_mock, follow_links=True)

    assert list(iterator.iter(
        Requirement.parse('pex'))) == [SourcePackage(pex_url)]
    assert len(crawler_mock.crawl.mock_calls) == 1
    _, _, kwargs = crawler_mock.crawl.mock_calls[0]
    assert kwargs == {'follow_links': True}
コード例 #11
0
ファイル: test_resolver.py プロジェクト: pfmoore/pex
def test_resolvable_set_constraint_and_non_constraint():
  builder = ResolverOptionsBuilder()
  rs = _ResolvableSet()
  constraint = ResolvableRequirement.from_string('foo', builder)
  constraint.is_constraint = True

  package = SourcePackage.from_href('foo-2.3.4.tar.gz')

  rq = ResolvableRequirement.from_string('foo', builder)
  rs.merge(constraint, [package])
  rs.merge(rq, [package])

  assert rs.packages() == [(rq, set([package]), None, False)]
コード例 #12
0
ファイル: test_resolver.py プロジェクト: pfmoore/pex
def test_resolver_with_constraint():
  builder = ResolverOptionsBuilder()
  r = Resolver()
  rs = _ResolvableSet()
  constraint = ResolvableRequirement.from_string('foo', builder)
  constraint.is_constraint = True

  package = SourcePackage.from_href('foo-2.3.4.tar.gz')

  rq = ResolvableRequirement.from_string('foo', builder)
  rs.merge(constraint, [package])
  rs.merge(rq, [package])
  assert r.resolve([], resolvable_set=rs) == []
コード例 #13
0
def test_resolvable_set_constraint_and_non_constraint():
  builder = ResolverOptionsBuilder()
  rs = _ResolvableSet()
  constraint = ResolvableRequirement.from_string('foo', builder)
  constraint.is_constraint = True

  package = SourcePackage.from_href('foo-2.3.4.tar.gz')

  rq = ResolvableRequirement.from_string('foo', builder)
  rs.merge(constraint, [package])
  rs.merge(rq, [package])

  assert rs.packages() == [(rq, set([package]), None, False)]
コード例 #14
0
def test_iter_ordering():
    pi = PythonInterpreter.get()
    tgz = SourcePackage('psutil-0.6.1.tar.gz')
    egg = EggPackage('psutil-0.6.1-py%s-%s.egg' %
                     (pi.python, get_build_platform()))
    whl = WheelPackage(
        'psutil-0.6.1-cp%s-none-%s.whl' %
        (pi.python.replace('.', ''), get_build_platform().replace(
            '-', '_').replace('.', '_').lower()))
    req = Requirement.parse('psutil')

    assert list(FakeIterator([tgz, egg, whl]).iter(req)) == [whl, egg, tgz]
    assert list(FakeIterator([egg, tgz, whl]).iter(req)) == [whl, egg, tgz]
コード例 #15
0
def test_href_translation():
    VERSIONS = ['0.4.0', '0.4.1', '0.5.0', '0.6.0']

    def fake_link(version):
        return 'http://www.example.com/foo/bar/psutil-%s.tar.gz' % version

    fc = FakeCrawler([fake_link(v) for v in VERSIONS])
    ob = Iterator(crawler=fc)

    for v in VERSIONS:
        pkgs = list(ob.iter(Requirement.parse('psutil==%s' % v)))
        assert len(pkgs) == 1, 'Version: %s' % v
        assert pkgs[0] == SourcePackage(fake_link(v))

    assert list(ob.iter(Requirement.parse('psutil>=0.5.0'))) == [
        SourcePackage(fake_link('0.6.0')),
        SourcePackage(fake_link('0.5.0'))
    ]

    assert list(ob.iter(Requirement.parse('psutil'))) == [
        SourcePackage(fake_link(v)) for v in reversed(VERSIONS)
    ]
コード例 #16
0
def test_resolver_with_constraint():
  builder = ResolverOptionsBuilder()
  r = Resolver()
  rs = _ResolvableSet()
  constraint = ResolvableRequirement.from_string('foo', builder)
  constraint.is_constraint = True

  package = SourcePackage.from_href('foo-2.3.4.tar.gz')

  rq = ResolvableRequirement.from_string('foo', builder)
  rs.merge(constraint, [package])
  rs.merge(rq, [package])
  assert r.resolve([], resolvable_set=rs) == []
コード例 #17
0
def test_sorter_sort():
  pi = PythonInterpreter.get()
  tgz = SourcePackage('psutil-0.6.1.tar.gz')
  egg = EggPackage('psutil-0.6.1-py%s-%s.egg' % (pi.python, get_build_platform()))
  whl = WheelPackage('psutil-0.6.1-cp%s-none-%s.whl' % (
      pi.python.replace('.', ''),
      get_build_platform().replace('-', '_').replace('.', '_').lower()))

  assert Sorter().sort([tgz, egg, whl]) == [whl, egg, tgz]
  assert Sorter().sort([egg, tgz, whl]) == [whl, egg, tgz]

  # test unknown type
  sorter = Sorter(precedence=(EggPackage, WheelPackage))
  assert sorter.sort([egg, tgz, whl], filter=False) == [egg, whl, tgz]
  assert sorter.sort([egg, tgz, whl], filter=True) == [egg, whl]
コード例 #18
0
ファイル: test_resolver.py プロジェクト: pfmoore/pex
def test_constraints_range():
  builder = ResolverOptionsBuilder()
  rs = _ResolvableSet()
  req = ResolvableRequirement.from_string("foo>0.5", builder)
  constraint = ResolvableRequirement.from_string("foo<0.9", builder)
  constraint.is_constraint = True

  version_packages = []
  for version in range(1, 10):
    version_string = "foo-0.{0}.tar.gz".format(version)
    package = SourcePackage.from_href(version_string)
    version_packages.append(package)
  rs.merge(req, version_packages[4:])
  rs.merge(constraint, version_packages[:8])
  assert rs.packages() == [(req, set(version_packages[4:8]), None, False)]
コード例 #19
0
def test_constraints_range():
  builder = ResolverOptionsBuilder()
  rs = _ResolvableSet()
  req = ResolvableRequirement.from_string("foo>0.5", builder)
  constraint = ResolvableRequirement.from_string("foo<0.9", builder)
  constraint.is_constraint = True

  version_packages = []
  for version in range(1, 10):
    version_string = "foo-0.{0}.tar.gz".format(version)
    package = SourcePackage.from_href(version_string)
    version_packages.append(package)
  rs.merge(req, version_packages[4:])
  rs.merge(constraint, version_packages[:8])
  assert rs.packages() == [(req, set(version_packages[4:8]), None, False)]
コード例 #20
0
def assert_iteration(all_versions, *expected_versions, **iterator_kwargs):
    def package_url(version):
        return 'https://pypi.org/packages/source/p/pex/pex-%s.tar.gz' % version

    urls = [package_url(v) for v in all_versions]
    crawler_mock = mock.create_autospec(Crawler, spec_set=True)
    crawler_mock.crawl.return_value = urls
    iterator = Iterator(crawler=crawler_mock,
                        follow_links=True,
                        **iterator_kwargs)

    assert list(iterator.iter(Requirement.parse('pex'))) == [
        SourcePackage(package_url(v)) for v in expected_versions
    ]
    assert len(crawler_mock.crawl.mock_calls) == 1
    _, _, kwargs = crawler_mock.crawl.mock_calls[0]
    assert kwargs == {'follow_links': True}
コード例 #21
0
ファイル: test_package.py プロジェクト: zuoxiaolei/pex
def test_source_packages():
  for ext in ('.tar.gz', '.tar', '.tgz', '.zip', '.tar.bz2'):
    sl = SourcePackage('a_p_r-3.1.3' + ext)
    assert sl._name == 'a_p_r'
    assert sl.name == 'a-p-r'
    assert sl.raw_version == '3.1.3'
    assert sl.version == parse_version(sl.raw_version)
    for req in ('a_p_r', 'a_p_r>2', 'a_p_r>3', 'a_p_r>=3.1.3', 'a_p_r==3.1.3', 'a_p_r>3,<3.5'):
      assert sl.satisfies(req)
      assert sl.satisfies(Requirement.parse(req))
    for req in ('foo', 'a_p_r==4.0.0', 'a_p_r>4.0.0', 'a_p_r>3.0.0,<3.0.3', 'a==3.1.3'):
      assert not sl.satisfies(req)
  sl = SourcePackage('python-dateutil-1.5.tar.gz')
  assert sl.name == 'python-dateutil'
  assert sl.raw_version == '1.5'
コード例 #22
0
def test_resolvable_set_built():
  builder = ResolverOptionsBuilder()
  rs = _ResolvableSet()
  rq = ResolvableRequirement.from_string('foo', builder)
  source_pkg = SourcePackage.from_href('foo-2.3.4.tar.gz')
  binary_pkg = EggPackage.from_href('foo-2.3.4-py3.4.egg')

  rs.merge(rq, [source_pkg])
  assert rs.get('foo') == set([source_pkg])
  assert rs.packages() == [(rq, set([source_pkg]), None, False)]

  with pytest.raises(Unsatisfiable):
    rs.merge(rq, [binary_pkg])

  updated_rs = rs.replace_built({source_pkg: binary_pkg})
  updated_rs.merge(rq, [binary_pkg])
  assert updated_rs.get('foo') == set([binary_pkg])
  assert updated_rs.packages() == [(rq, set([binary_pkg]), None, False)]
コード例 #23
0
def test_package_precedence():
  source = SourcePackage('psutil-0.6.1.tar.gz')
  egg = EggPackage('psutil-0.6.1-py2.6.egg')
  whl = WheelPackage('psutil-0.6.1-cp26-none-macosx_10_4_x86_64.whl')

  # default precedence
  assert Sorter.package_precedence(whl) > Sorter.package_precedence(egg)
  assert Sorter.package_precedence(egg) > Sorter.package_precedence(source)
  assert Sorter.package_precedence(whl) > Sorter.package_precedence(source)

  # overridden precedence
  PRECEDENCE = (EggPackage, WheelPackage)
  assert Sorter.package_precedence(source, PRECEDENCE) == (
      source.version, -1, 0, True, source.url)  # unknown rank
  assert Sorter.package_precedence(whl, PRECEDENCE) > Sorter.package_precedence(
      source, PRECEDENCE)
  assert Sorter.package_precedence(egg, PRECEDENCE) > Sorter.package_precedence(
      whl, PRECEDENCE)
コード例 #24
0
ファイル: test_resolver.py プロジェクト: pfmoore/pex
def test_resolvable_set_built():
  builder = ResolverOptionsBuilder()
  rs = _ResolvableSet()
  rq = ResolvableRequirement.from_string('foo', builder)
  source_pkg = SourcePackage.from_href('foo-2.3.4.tar.gz')
  binary_pkg = EggPackage.from_href('foo-2.3.4-py3.4.egg')

  rs.merge(rq, [source_pkg])
  assert rs.get('foo') == set([source_pkg])
  assert rs.packages() == [(rq, set([source_pkg]), None, False)]

  with pytest.raises(Unsatisfiable):
    rs.merge(rq, [binary_pkg])

  updated_rs = rs.replace_built({source_pkg: binary_pkg})
  updated_rs.merge(rq, [binary_pkg])
  assert updated_rs.get('foo') == set([binary_pkg])
  assert updated_rs.packages() == [(rq, set([binary_pkg]), None, False)]
コード例 #25
0
ファイル: test_resolver.py プロジェクト: steveniemitz/pex
def test_resolvable_set():
  builder = ResolverOptionsBuilder()
  rs = _ResolvableSet()
  rq = ResolvableRequirement.from_string('foo[ext]', builder)
  source_pkg = SourcePackage.from_href('foo-2.3.4.tar.gz')
  binary_pkg = EggPackage.from_href('foo-2.3.4-py3.4.egg')

  rs.merge(rq, [source_pkg, binary_pkg])
  assert rs.get('foo') == set([source_pkg, binary_pkg])
  assert rs.packages() == [(rq, set([source_pkg, binary_pkg]), None)]

  # test methods
  assert rs.extras('foo') == set(['ext'])

  # test filtering
  rs.merge(rq, [source_pkg])
  assert rs.get('foo') == set([source_pkg])

  with pytest.raises(Unsatisfiable):
    rs.merge(rq, [binary_pkg])
コード例 #26
0
def test_resolvable_set():
  builder = ResolverOptionsBuilder()
  rs = _ResolvableSet()
  rq = ResolvableRequirement.from_string('foo[ext]', builder)
  source_pkg = SourcePackage.from_href('foo-2.3.4.tar.gz')
  binary_pkg = EggPackage.from_href('Foo-2.3.4-py3.4.egg')

  rs.merge(rq, [source_pkg, binary_pkg])
  assert rs.get(source_pkg.name) == set([source_pkg, binary_pkg])
  assert rs.get(binary_pkg.name) == set([source_pkg, binary_pkg])
  assert rs.packages() == [(rq, set([source_pkg, binary_pkg]), None, False)]

  # test methods
  assert rs.extras('foo') == set(['ext'])
  assert rs.extras('Foo') == set(['ext'])

  # test filtering
  rs.merge(rq, [source_pkg])
  assert rs.get('foo') == set([source_pkg])
  assert rs.get('Foo') == set([source_pkg])

  with pytest.raises(Unsatisfiable):
    rs.merge(rq, [binary_pkg])
コード例 #27
0
ファイル: test_resolvable.py プロジェクト: jsirois/pex
def test_resolvable_requirement():
  req = 'foo[bar]==2.3.4'
  resolvable = ResolvableRequirement.from_string(req, ResolverOptionsBuilder(fetchers=[]))
  assert resolvable.requirement == pkg_resources.Requirement.parse('foo[bar]==2.3.4')
  assert resolvable.name == 'foo'
  assert resolvable.exact is True
  assert resolvable.extras() == ['bar']
  assert resolvable.options._fetchers == []
  assert resolvable.packages() == []

  source_pkg = SourcePackage.from_href('foo-2.3.4.tar.gz')
  mock_iterator = mock.create_autospec(Iterator, spec_set=True)
  mock_iterator.iter.return_value = iter([source_pkg])
  assert resolvable.compatible(mock_iterator) == [source_pkg]
  assert mock_iterator.iter.mock_calls == [
      mock.call(pkg_resources.Requirement.parse('foo[bar]==2.3.4'))]

  # test non-exact
  resolvable = ResolvableRequirement.from_string('foo', ResolverOptionsBuilder())
  assert resolvable.exact is False

  # test Resolvable.get, which should delegate to a ResolvableRequirement in this case
  assert Resolvable.get('foo') == ResolvableRequirement.from_string(
      'foo', ResolverOptionsBuilder())
コード例 #28
0
ファイル: test_resolvable.py プロジェクト: jsirois/pex
def test_resolvable_package():
  builder = ResolverOptionsBuilder()
  source_name = 'foo-2.3.4.tar.gz'
  pkg = SourcePackage.from_href(source_name)
  resolvable = ResolvablePackage.from_string(source_name, builder)
  assert resolvable.packages() == [pkg]

  mock_iterator = mock.create_autospec(Iterator, spec_set=True)
  mock_iterator.iter.return_value = iter([])
  # fetchers are currently unused for static packages.
  assert resolvable.compatible(mock_iterator) == []
  assert mock_iterator.iter.mock_calls == []
  assert resolvable.name == 'foo'
  assert resolvable.exact is True
  assert resolvable.extras() == []

  resolvable = ResolvablePackage.from_string(source_name + '[extra1,extra2]', builder)
  assert resolvable.extras() == ['extra1', 'extra2']

  assert Resolvable.get('foo-2.3.4.tar.gz') == ResolvablePackage.from_string(
      'foo-2.3.4.tar.gz', builder)

  with pytest.raises(ResolvablePackage.InvalidRequirement):
    ResolvablePackage.from_string('foo', builder)
コード例 #29
0
ファイル: test_package.py プロジェクト: butlern/pex
 def source_package(version):
     return SourcePackage('setuptools-%s.tar.gz' % version)