Debian Codegraph @

tests/test_requirement.py

raw symbols SCIP
1 # encoding: utf-8
2
3 # This file is part of requirements-parser library.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #
17 # SPDX-License-Identifier: Apache-2.0
18
19 from typing import Tuple
20 from unittest import TestCase
21
22 from requirements.requirement import Requirement
23
24
25 class TestRequirement(TestCase):
26
27 @staticmethod
28 def get_reqs(requirement_1: str, requirement_2: str) -> Tuple[Requirement, Requirement]:
29 return (Requirement.parse(requirement_1),
30 Requirement.parse(requirement_2))
31
32 def test_simple_equality(self) -> None:
33 self.assertEqual(*TestRequirement.get_reqs('pylib==1.0.0', 'pylib==1.0.0'))
34
35 def test_equality_no_specifiers(self) -> None:
36 self.assertEqual(*TestRequirement.get_reqs('pylib', 'pylib'))
37
38 def test_simple_inequality(self) -> None:
39 self.assertNotEqual(*TestRequirement.get_reqs('pylib==1.0.0', 'pylib==1.0.1'))
40
41 def test_spec_order_equality(self) -> None:
42 """
43 The same specifications, in a different order, are still equal
44 """
45 self.assertEqual(*TestRequirement.get_reqs('pylib>=1.0,<2.0', 'pylib<2.0,>=1.0'))
46
47 def test_vcs_equality(self) -> None:
48 self.assertEqual(*TestRequirement.get_reqs(
49 '-e git://git.example.com/MyProject.git@da39a3ee#egg=MyProject',
50 '-e git://git.example.com/MyProject.git@da39a3ee#egg=MyProject'
51 ))
52
53 def test_vcs_hash_inequality(self) -> None:
54 self.assertNotEqual(*TestRequirement.get_reqs(
55 '-e git://git.example.com/MyProject.git@123#egg=MyProject',
56 '-e git://git.example.com/MyProject.git@abc#egg=MyProject'
57 ))