# -*- encoding: UTF8 -*- # Test harness for P4Triggers.py and a sub-class thereof """ Test script for P4Triggers framework """ from __future__ import print_function import sys import unittest import os import re import P4 from p4testutils import TestCase, P4Server, localDirectory, create_file, append_to_file parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.insert(0, parent_dir) import P4Triggers LOGGER_NAME = "TestP4Triggers" LOG_FILE = "log-TestP4Triggers.log" class SampleTrigger(P4Triggers.P4Trigger): """See module doc string for details""" def __init__(self, *args, **kwargs): P4Triggers.P4Trigger.__init__(self, **kwargs) self.parse_args(__doc__, args) def add_parse_args(self, parser): """Specific args for this trigger - also calls super class to add common trigger args""" parser.add_argument('-c', '--config-file', default=None, help="Configuration file for trigger. Default: CheckFixes.yaml") parser.add_argument('change', help="Change to validate - %%change%% argument from triggers entry.") super(SampleTrigger, self).add_parse_args(parser) class TestP4Triggers(TestCase): def __init__(self, methodName='runTest'): super(TestP4Triggers, self).__init__(LOGGER_NAME, LOG_FILE, methodName=methodName) def setUp(self): pass def tearDown(self): pass def testP4Triggers(self): """check that fixes are appropriate controlled""" trig_args = ["-p", "testport", "-u", "testuser", "99"] trig = SampleTrigger(*trig_args) self.assertEqual('p4triggers.log', trig.options.log) self.assertEqual('99', trig.options.change) self.assertEqual('testport', trig.options.port) self.assertEqual('testuser', trig.options.user) trig_args = ["-p", "testport", "-u", "testuser", "-L", "mylog.log", "99"] trig = SampleTrigger(*trig_args) self.assertEqual('mylog.log', trig.options.log) self.assertEqual('99', trig.options.change) os.environ["LOGS"] = "/tmp" trig_args = ["-p", "testport", "-u", "testuser", "99"] trig = SampleTrigger(*trig_args) self.assertEqual('p4triggers.log', trig.options.log) self.assertEqual('99', trig.options.change) trig_args = ["-p", "testport", "-u", "testuser", "-L", "mylog.log", "99"] trig = SampleTrigger(*trig_args) self.assertEqual('mylog.log', trig.options.log) self.assertEqual('99', trig.options.change) if __name__ == '__main__': unittest.main()
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 29143 | C. Thomas Tyler |
Released SDP 2022.1.29141 (2022/10/29). Copy Up using 'p4 copy -r -b perforce_software-sdp-dev'. |
||
#1 | 27331 | C. Thomas Tyler |
Released SDP 2020.1.27325 (2021/01/29). Copy Up using 'p4 copy -r -b perforce_software-sdp-dev'. |
||
//guest/perforce_software/sdp/dev/Unsupported/Samples/triggers/tests/TestP4Triggers.py | |||||
#1 | 26652 | Robert Cowham |
This is Tom's change: Introduced new 'Unsupported' directory to clarify that some files in the SDP are not officially supported. These files are samples for illustration, to provide examples, or are deprecated but not yet ready for removal from the package. The Maintenance and many SDP triggers have been moved under here, along with other SDP scripts and triggers. Added comments to p4_vars indicating that it should not be edited directly. Added reference to an optional site_global_vars file that, if it exists, will be sourced to provide global user settings without needing to edit p4_vars. As an exception to the refactoring, the totalusers.py Maintenance script will be moved to indicate that it is supported. Removed settings to support long-sunset P4Web from supported structure. Structure under new .../Unsupported folder is: Samples/bin Sample scripts. Samples/triggers Sample trigger scripts. Samples/triggers/tests Sample trigger script tests. Samples/broker Sample broker filter scripts. Deprecated/triggers Deprecated triggers. To Do in a subsequent change: Make corresponding doc changes. |
||
//guest/perforce_software/sdp/dev/Server/Unix/p4/common/bin/triggers/tests/TestP4Triggers.py | |||||
#1 | 23671 | Robert Cowham | Tweak log setting for trigger logs |