forked from MuhmdRaouf/DependencyFetcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestVersionMatching.py
executable file
·66 lines (51 loc) · 2.08 KB
/
TestVersionMatching.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import unittest
import os
from DependencyFetcher import Fetcher
class TestVersionMatching(unittest.TestCase):
@classmethod
def setUp(self):
file = open("pom-test.xml", "w+")
file.write(
"""
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<dependencies>
<dependency>
<groupId>dummy-time</groupId>
<artifactId>dummy</artifactId>
<version>1.3.4</version>
</dependency>
</dependencies>
</project>
""")
file.close()
def tearDown(self):
os.remove("pom-test.xml")
def testGettingNearestLowerVersionWhenNoMatchFound(self):
try:
targetJarName = "dummy-1.2.6.jar"
open("./lib/dummy-1.2.6.jar", "w+").close()
open("./lib/dummy-1.1.6.jar", "w+").close()
open("./lib/dummy-1.2.1.jar", "w+").close()
elements = Fetcher.parseAllDependencyFromPom('./pom-test.xml')
fileName = Fetcher.findJarFilenameForDependency("./lib", elements[0])
self.assertEqual(targetJarName, fileName)
finally:
os.remove("./lib/dummy-1.2.6.jar")
os.remove("./lib/dummy-1.1.6.jar")
os.remove("./lib/dummy-1.2.1.jar")
def testGettingNearestUpperVesrionWhenNoMatchFound(self):
try:
targetJarName = "dummy-1.4.2.jar"
open("./lib/dummy-1.4.2.jar", "w+").close()
open("./lib/dummy-1.4.6.jar", "w+").close()
open("./lib/dummy-1.5.1.jar", "w+").close()
elements = Fetcher.parseAllDependencyFromPom('./pom-test.xml')
fileName = Fetcher.findJarFilenameForDependency("./lib", elements[0])
self.assertEqual(targetJarName, fileName)
finally:
os.remove("./lib/dummy-1.4.2.jar")
os.remove("./lib/dummy-1.4.6.jar")
os.remove("./lib/dummy-1.5.1.jar")
if __name__ == '__main__':
unittest.main()