1 | from fileinput import filename
|
---|
2 | import json
|
---|
3 | from pathlib import Path
|
---|
4 | import unittest
|
---|
5 | from unittest.mock import Mock
|
---|
6 |
|
---|
7 | from pyson.ObjectMapper import ObjectMapper
|
---|
8 | from tudelft_utilities_logging.ReportToLogger import ReportToLogger
|
---|
9 |
|
---|
10 | from geniusweb.protocol.NegoSettings import NegoSettings
|
---|
11 | from geniusweb.simplerunner.ClassPathConnectionFactory import ClassPathConnectionFactory
|
---|
12 | from geniusweb.simplerunner.NegoRunner import NegoRunner
|
---|
13 | from geniusweb.simplerunner.Runner import Runner
|
---|
14 |
|
---|
15 |
|
---|
16 | class SessionRunnerE2ETest(unittest.TestCase):
|
---|
17 | '''
|
---|
18 | E2E test doing a full real run of a session with real agents and protocol.
|
---|
19 | NOTICE This will exercise a full system to errors here may point far outside
|
---|
20 | this module.
|
---|
21 | '''
|
---|
22 | TEST_RUNTIME = 5000
|
---|
23 | jackson = ObjectMapper()
|
---|
24 | logger = Mock(ReportToLogger("test"))
|
---|
25 | filename:str
|
---|
26 | runner:Runner
|
---|
27 |
|
---|
28 | params = ["test/resources/settings.json",
|
---|
29 | # "test/resources/settings2.json" , PARTIALORDERING NOT YET
|
---|
30 | "test/resources/settingsbadprofile.json",
|
---|
31 | # "test/resources/shaoptoursettings.json", ALLPERMUTATIONSETTINGS NOT YET
|
---|
32 | "test/resources/mopac.json"
|
---|
33 | # "test/resources/tournament.json" ALLPERMUTATIONSETTINGS NOT YET
|
---|
34 | ]
|
---|
35 |
|
---|
36 | def testAll(self):
|
---|
37 | '''
|
---|
38 | runs all the tests. Python has no standard 'parameterized' mechanism
|
---|
39 | so we have to do it ourselves.
|
---|
40 | '''
|
---|
41 | for filename in self.params:
|
---|
42 | self.filename = filename
|
---|
43 | with self.subTest("before " + self.filename):
|
---|
44 | self.before()
|
---|
45 | with self.subTest("runMain" + self.filename):
|
---|
46 | self.runTestMainFunction()
|
---|
47 |
|
---|
48 | def before(self):
|
---|
49 | print("Running from file " + self.filename)
|
---|
50 | serialized = Path(self.filename).read_text("utf-8")
|
---|
51 | settings = self.jackson.parse(json.loads(serialized), NegoSettings)
|
---|
52 | self.runner = Runner(settings, ClassPathConnectionFactory(),
|
---|
53 | self.logger, self.TEST_RUNTIME)
|
---|
54 |
|
---|
55 | def runTestMainFunction(self):
|
---|
56 | NegoRunner.main([self.filename])
|
---|
57 |
|
---|
58 | def runTest(self):
|
---|
59 | self.runner.run()
|
---|
60 | print("Final state:\n" + str(self.runner.getProtocol().getState()))
|
---|
61 | self.assertTrue(self.runner.isProperlyStopped())
|
---|
62 | # check no warnings and more severe
|
---|
63 | self.asssertEqual([], self.logger.log.call_args_list)
|
---|