def test_fix_pin_detects_version_conflict(): """Check that package x can't be locked to versions 1 and 2""" env = Environment('', ignore={'x': '1'}) ignored_pin = env.fix_pin('x==1') assert ignored_pin is None with pytest.raises(RuntimeError): env.fix_pin('x==2')
def test_forbid_post_releases(): """Test postXXX versions are kept if allow_post=True""" pin = 'pycodestyle==2.3.1.post2231 # via flake8' with mock.patch.dict(OPTIONS, {'forbid_post': ['env']}): env = Environment('env') result = env.fix_pin(pin) assert result == PIN
def test_pin_is_ommitted_if_set_to_ignore(): """Test ignored files won't pass""" dedup = PackageDeduplicator() dedup.on_discover([{ 'in_path': 'a', 'refs': ['b'] }, { 'in_path': 'b', 'refs': [] }]) dedup.register_packages_for_env('b', {'pycodestyle': '2.3.1'}) env = Environment('a', deduplicator=dedup) result = env.fix_pin(PIN) assert result is None
def test_fix_pin_detects_version_conflict(): """Check that package x can't be locked to versions 1 and 2""" dedup = PackageDeduplicator() dedup.on_discover([{ 'in_path': 'a', 'refs': ['b'] }, { 'in_path': 'b', 'refs': [] }]) dedup.register_packages_for_env('b', {'x': '1'}) env = Environment('a', deduplicator=dedup) ignored_pin = env.fix_pin('x==1') assert ignored_pin is None with pytest.raises(RuntimeError): env.fix_pin('x==2')
def test_concatenation(): """Check lines are joined and extra spaces removed""" lines = Environment.concatenated([ 'abc \\\n', ' 123 \\\n', '?\n', 'MMM\n', ]) assert list(lines) == ['abc 123 ?', 'MMM']
def test_split_header(): """Check that default header is parsed from autogenerated base.txt""" with open(os.path.join('requirements', 'base.txt')) as fp: header, _ = Environment.split_header(fp) expected = [line + '\n' for line in DEFAULT_HEADER.splitlines()] assert header[1:] == expected
def test_parse_references(in_path, refs): """Check references are parsed for sample files""" env = Environment('') result = env.parse_references(os.path.join('requirements', in_path)) assert result == refs
def test_post_releases_are_kept_by_default(): """Test postXXX versions are truncated to release""" pin = 'pycodestyle==2.3.1.post2231 # via flake8' env = Environment('') result = env.fix_pin(pin) assert result == pin
def test_no_fix_incompatible_pin(): """Test dependency is left unchanged be default""" env = Environment('') result = env.fix_pin(PIN) assert result == PIN
def test_fix_compatible_pin(): """Test == is replaced with ~= for compatible dependencies""" env = Environment('xxx') with mock.patch.dict(OPTIONS, {'compatible_patterns': ['pycode*']}): result = env.fix_pin(PIN) assert result == CMPT
def test_forbid_post_releases(): """Test postXXX versions are kept if allow_post=True""" pin = 'pycodestyle==2.3.1.post2231 # via flake8' env = Environment('', forbid_post=True) result = env.fix_pin(pin) assert result == PIN
def test_pin_is_ommitted_if_set_to_ignore(): """Test ignored files won't pass""" env = Environment('', ignore={'pycodestyle': '2.3.1'}) result = env.fix_pin(PIN) assert result is None