def testBooleanPositionalArgumentAllowsFalse(self): cli = Cli(BooleanPositionalOptions) myOptions = cli.parseArguments(['false']) assert_false(myOptions.isTest()) myOptions = cli.parseArguments(['False']) assert_false(myOptions.isTest()) myOptions = cli.parseArguments(['fAlse']) assert_false(myOptions.isTest()) myOptions = cli.parseArguments(['FALSE']) assert_false(myOptions.isTest())
def testBooleanPositionalArgumentAllowsTrue(self): cli = Cli(BooleanPositionalOptions) myOptions = cli.parseArguments(['true']) assert_true(myOptions.isTest()) myOptions = cli.parseArguments(['True']) assert_true(myOptions.isTest()) myOptions = cli.parseArguments(['tRue']) assert_true(myOptions.isTest()) myOptions = cli.parseArguments(['TRUE']) assert_true(myOptions.isTest())
def main(): try: #parse the commandline myoptions = Cli(MyOptions).parseArguments() except CliHelpError as helpError: print helpError return 0 #weather functions get_weather(myoptions.getweather_location(), myoptions.getmetric_unit()) #create flags for Google Services flags = Flags.Flags(myoptions.getauth_host_name(), myoptions.getauth_host_port(), myoptions.isnoauth_local_webserver(), myoptions.getlogging_level()) #Create google services object. This get carried around for google api functions. google_services = GoogleServices.GoogleServices(myoptions.getclient_secret(), flags) try: #connect, auth and return a connected service object google_services = google_services.startgoogleservices() except AccessTokenRefreshError: print("The credentials have been revoked or expired, please re-run the application to re-authorize") return 0 #returns a selected calendar - either from one stored in user file or return an option select_calendar = CalendarSelection.calendarlisting(google_services) calendarid = select_calendar.return_calendar_id() EventListing.event_listing(google_services, calendarid) #start twisted event loop for fetching weather data. reactor.run()
def testPositionalArgumentsAloneRetrievedCorrectly(self): myOptions = Cli(MyOptions).parseArguments(['pA', 'pB']) assert_equals(myOptions.getPositionalArgumentA(), 'pA') assert_equals(myOptions.getPositionalArgumentB(), 'pB')
def testPositionalArgumentsWithRandomPositionValuesRetrievedInCorrectOrder(self): myOptions = Cli(RandomPositionsOptions).parseArguments(['1', '2', '3']) assert_equals(myOptions.getPositionalArgumentMinus1(), '1') assert_equals(myOptions.getPositionalArgument8(), '2') assert_equals(myOptions.getPositionalArgument12(), '3')
def testMultiValuedWithMinOptionDoesNotThrowsIfAtLeastMinValuesGiven(self): cli = Cli(OptionWithMin) options = cli.parseArguments(['--option', 'blue']) assert_equals(options.getOption(), ['blue'])
def testMultiValuedOptionWithJustOneValueSpecifiedReturnsItAsAList(self): myOptions = Cli(MyOptions).parseArguments(['--multiValuedOption', 'one']) assert_equals(myOptions.getMultiValuedOption(), ['one'])
def testMultiValuedWithMaxOptionDoesNotThrowsIfLessThanMaxValuesGiven(self): cli = Cli(OptionWithMax) options = cli.parseArguments(['--option', 'a', 'b']) assert_equals(options.getOption(), ['a', 'b'])
def testNumericValueFormatterReturnsBinaryNumberAsNumberType(self): myOptions = Cli(MyOptions).parseArguments(['--numericOption', '0b1010']) assert_equals(myOptions.getNumericOption(), [0b1010])
def testInheritedOptionIsParsedCorrectly(self): myOptions = Cli(MyOptions).parseArguments(['--simpleOption', 'valueA', '--deleteFiles']) assert_equals(myOptions.getSimpleOption(), 'valueA') assert_true(myOptions.isDeleteFiles())
def testUnspecifiedNonMandatoryOptionReturnsNone(self): myOptions = Cli(MyOptions).parseArguments(['--mandatoryOption', 'value']) assert_true(myOptions.getOption() is None)
def testPresentBooleanOptionReturnsTrue(self): myOptions = Cli(MyOptions).parseArguments(['--deleteFiles']) assert_true(myOptions.isDeleteFiles())
def testMissingBooleanOptionReturnsFalse(self): myOptions = Cli(MyOptions).parseArguments([]) assert_false(myOptions.isDeleteFiles())
def testUnspecifiedNonBooleanOptionWithNoDefaultReturnsNone(self): myOptions = Cli(MyOptions).parseArguments([]) assert_true(myOptions.getSimpleOption() is None)
def testNonBooleanOptionWithSingleValueReturnsSpecifiedValue(self): myOptions = Cli(MyOptions).parseArguments(['--simpleOption', 'valueA']) assert_equals(myOptions.getSimpleOption(), 'valueA')
def testNumericValueFormatterReturnsOctalNumberAsNumberType(self): myOptions = Cli(MyOptions).parseArguments(['--numericOption', '017']) assert_equals(myOptions.getNumericOption(), [017])
import argparse from Serv import Serv from Cli import Cli from Api import Api parser = argparse.ArgumentParser() parser.add_argument('port', type=int, nargs='?', default=4444) args = parser.parse_args() if __name__ == '__main__': serv = Serv(args.port) print("Started the node on " + serv.addr) api = Api(serv) cli = Cli(api) serv.start() cli.start() ''' //Checklist *# mesh network *# join operation *# New machines join the network by sending a join message to one of the machines already in the network. *# The address of the new host is thereupon propagated in the network. *# Hosts also need to be able to sign off from the network again. *# One node in the network needs to be elected as master node. The master node stores a string variable that is initially empty. *# Start message *# The master node needs to be elected by the Bully algorithm. *# In case the current master node signs off or fails a new master has to be elected. *# The process takes 20 seconds. During this time all the nodes in the network do the following: LOOP
def testPositionalArgumentsCanHaveValueFormatter(self): myPositionalArguments = Cli(MyPositionalArguments).parseArguments(['1024']) assert_equals(myPositionalArguments.getSize(), 1024)
def testOptionWithShortNameCanBeSpecifiedUsingShortName(self): myOptions = Cli(MyOptions).parseArguments(['-o', 'abc']) assert_equals(myOptions.getOptionWithShortName(), 'abc')
def testUnspecifiedMultiValuedOptionReturnsDefaults(self): myOptions = Cli(MyOptions).parseArguments([]) assert_equals(myOptions.getMultiValuedOption(), ['abc', 'def'])
def testMissingBooleanOptionWithShortNameReturnsFalse(self): myOptions = Cli(MyOptions).parseArguments([]) assert_false(myOptions.isBooleanOptionWithShortName())
def testMultiValuedOptionReturnsAllSpecifiedValues(self): myOptions = Cli(MyOptions).parseArguments(['--multiValuedOption', 'one', 'two', 'three']) assert_equals(myOptions.getMultiValuedOption(), ['one', 'two', 'three'])
def testBooleanOptionWithShortNameCanBeSpecifiedUsingShortName(self): myOptions = Cli(MyOptions).parseArguments(['-i']) assert_true(myOptions.isBooleanOptionWithShortName())
def testSinglePositionalArgumentRetrievedAsAValue(self): myOptions = Cli(SinglePositionalOptions).parseArguments(['pA']) assert_equals(myOptions.getPositionalArgumentA(), 'pA')
def testNoValueFormatterSpecifiedReturnsStringType(self): myOptions = Cli(MyOptions).parseArguments(['--simpleOption', '123']) assert_equals(myOptions.getSimpleOption(), '123')
def testPositionalArgumentsAfterMultiValuedOptionalRetrievedCorrectly(self): myOptions = Cli(MultiValuedAndPositionalOptions).parseArguments(['--option', 'A', 'B', 'C', 'pA', 'pB']) assert_equals(myOptions.getOption(), ['A', 'B', 'C']) assert_equals(myOptions.getPositionalArgumentA(), 'pA') assert_equals(myOptions.getPositionalArgumentB(), 'pB')
def testNoValueFormatterSpecifiedWithNonStringDefaultListReturnsListOfStringType(self): myOptions = Cli(MyOptions).parseArguments([]) assert_equals(myOptions.getSimpleWithDefaultListOption(), ['123', '456'])
def testPositionalArgumentsAfterOptionalRetrievedCorrectly(self): myOptions = Cli(MyOptions).parseArguments(['--optionalA', 'A', '--optionalB', 'B', 'pA', 'pB']) assert_equals(myOptions.getOptionalA(), 'A') assert_equals(myOptions.getOptionalB(), 'B') assert_equals(myOptions.getPositionalArgumentA(), 'pA') assert_equals(myOptions.getPositionalArgumentB(), 'pB')
def testDigitStringValueFormatterReturnsStringType(self): myOptions = Cli(MyOptions).parseArguments(['--digitStringOption', '0123']) assert_equals(myOptions.getDigitStringOption(), '0123')
def testNumericValueFormatterReturnsHexadecimalNumberAsNumberType(self): myOptions = Cli(MyOptions).parseArguments(['--numericOption', '0xff', '0xEE']) assert_equals(myOptions.getNumericOption(), [0xff, 0xee])
import argparse from Serv import Serv from Cli import Cli from Api import Api parser = argparse.ArgumentParser() parser.add_argument('port', type=int, nargs='?', default=4444) args = parser.parse_args() if __name__ == '__main__': serv = Serv(args.port) print("Started the node on " + serv.addr) api = Api(serv) cli = Cli(api) serv.start() cli.start() ''' //Checklist *# mesh network *# join operation *# New machines join the network by sending a join message to one of the machines already in the network. *# The address of the new host is thereupon propagated in the network. *# Hosts also need to be able to sign off from the network again. *# One node in the network needs to be elected as master node. The master node stores a string variable that is initially empty. *# Start message *# The master node needs to be elected by the Bully algorithm. *# In case the current master node signs off or fails a new master has to be elected. *# The process takes 20 seconds. During this time all the nodes in the network do the following: LOOP a) Wait a random amount of time