Best Python code snippet using molecule_python
audit_types.py
Source:audit_types.py
...5############## VALUE_TYPES6class VALUE_TYPE:7 def __init__(self, value):8 self.value = value9 def _validate(self, value:any) -> bool:10 return True11 def __repr__(self) -> str:12 return "%s" % str(self.value)13class DWORD(VALUE_TYPE):14 15 def __init__(self, value:int):16 if value == 'MIN':17 value = 018 elif value == "MAX":19 value = 214748364720 if self._validate(value):21 self.value = int(value)22 else: 23 raise TypeError("%s is not a valid value for DWORD" % str(value))24 def _validate(self, value:int) -> bool:25 if isinstance(value, int):26 return value < 214748364827 28 elif isinstance(value, str):29 try:30 int(value)31 except ValueError:32 return False33 else:34 return int(value) < 214748364835 else:36 return False37 38 def __repr__(self) -> str:39 return "%d" % self.value40class RANGE(VALUE_TYPE):41 def __init__(self, minimum_value: DWORD, maximum_value: DWORD):42 if self._validate(minimum_value, maximum_value):43 self.value = (minimum_value, maximum_value)44 else: 45 raise TypeError("%s is not a valid value for RANGE" % str((minimum_value, maximum_value)))46 def _validate(self, minimum_value: DWORD, maximum_value: DWORD):47 if isinstance(minimum_value, DWORD) and isinstance( maximum_value, DWORD):48 return minimum_value < maximum_value49 else:50 return False51 def __repr__(self) -> str:52 return "[%d..%d]" % self.value53 54class POLICY_SET(VALUE_TYPE):55 def __init__(self, value:str):56 if self._validate(value):57 self.value = value58 59 else:60 raise TypeError("%s is not a valid value for POLICY_SET" % str(value))61 def convert_to_DWORD(self) -> DWORD:62 return DWORD(("Disabled","Enabled").index(self.value))63 def _validate(self, value:str)->bool:64 return value in ("Enabled","Disabled")65 def __repr__(self) -> str:66 return "\"%s\"" % self.value67class POLICY_DWORD(VALUE_TYPE):68 def __init__(self, value:(DWORD, RANGE)):69 if self._validate(value):70 self.value = value71 elif isinstance(value, convertable_type_list):72 self.value = value.convert_to_DWORD()73 else: 74 raise TypeError("%s is not a valid value for POLICY_DWORD" % str(value))75 def _validate(self, value: (DWORD, RANGE))->bool:76 return isinstance(value, (DWORD, RANGE)) 77 78 def __repr__(self) -> str:79 return "%s" % self.value80class POLICY_TEXT(VALUE_TYPE):81 def __init__(self, value:str):82 if self._validate(value):83 self.value = value84 else:85 raise TypeError("%s is not a valid value for POLICY_TEXT" % str(value))86 def _validate(self, value) -> bool:87 return isinstance(value, str)88 def __repr__(self) -> str:89 return "\"%s\"" % self.value90class POLICY_MULTI_TEXT(VALUE_TYPE):91 def __init__(self,value:[POLICY_TEXT]):92 if self._validate(value):93 self.value = tuple(value)94 else:95 raise TypeError("%s is not a valid value for POLICY_MULTI_TEXT" % str(value))96 def _validate(self, value:[POLICY_TEXT]) -> bool:97 if not isinstance(value, (list, tuple)):98 return False99 for x in value:100 if not isinstance(x, POLICY_TEXT):101 return False102 103 return True104 def __repr__(self) -> str:105 return str(self.value).replace(", "," && ").replace("(","").replace(")","").replace("'","\"")106class TIME_VALUE(VALUE_TYPE):107 def __init__(self, value:int):108 if self._validate(value):109 self.value = int(value)110 111 else:112 raise TypeError("%s is not a valid value for TIME" % str(value))113 def _validate(self, value:int)->bool:114 if isinstance(value, int):115 return True116 elif isinstance(value, str):117 try:118 int(value)119 except ValueError:120 return False121 else:122 return True123 else:124 return False125 def __repr__(self) -> str:126 return "%d" % self.value127class AUDIT_SET(VALUE_TYPE):128 def __init__(self,value:str):129 if " and " in value:130 value = value.replace(" and", ",")131 if self._validate(value):132 self.value = value133 else:134 raise TypeError("%s is not a valid value for AUDIT_SET" % str(value))135 def _validate(self, value:str)->bool:136 return value in ("No auditing", "Success", "Failure", "Success, Failure") 137 def __repr__(self):138 return "\"%s\"" % self.value139class DRIVER_SET(VALUE_TYPE):140 def __init__(self, value: str):141 if self._validate(value):142 self.value = value143 else:144 raise TypeError("%s is not a valid value for DRIVER_SET" % str(value))145 def _validate(self, value: str) -> bool:146 return value in ("Silent Succeed", "Warn but allow installation", "Do not allow installation")147 148 def __repr__(self) -> str:149 return "\"%s\"" % self.value150class LDAP_SET(VALUE_TYPE):151 def __init__(self, value: str):152 if self._validate(value):153 self.value = value154 else:155 raise TypeError("%s is not a valid value for LDAP_SET" % str(value))156 def _validate(self, value: str) -> bool:157 return value in ("None","Require Signing")158 159 def __repr__(self) -> str:160 return "\"%s\"" % self.value161class LOCKEDID_SET(VALUE_TYPE):162 def __init__(self, value: str):163 if self._validate(value):164 self.value = value165 else:166 raise TypeError("%s is not a valid value for LOCKEDID_SET" % str(value))167 def _validate(self, value: str) -> bool:168 return value in ("user display name, domain and user names", "user display name only", "do not display user information")169 170 def __repr__(self) -> str:171 return "\"%s\"" % self.value172class SMARTCARD_SET(VALUE_TYPE):173 174 def __init__(self, value: str):175 if self._validate(value):176 self.value = value177 else:178 raise TypeError("%s is not a valid value for SMARTCARD_SET" % str(value))179 def _validate(self, value: str) -> bool:180 return value in ("No action", "Lock Workstation", "Force logoff", "Disconnect if a remote terminal services session")181 182 def __repr__(self) -> str:183 return "\"%s\"" % self.value 184class LOCALACCOUNT_SET(VALUE_TYPE):185 def __init__(self, value: str):186 if self._validate(value):187 self.value = value188 else:189 raise TypeError("%s is not a valid value for LOCALACCOUNT_SET" % str(value))190 def _validate(self, value: str) -> bool:191 return value in ("Classic - local users authenticate as themselves", "Guest only - local users authenticate as guest")192 193 def __repr__(self) -> str:194 return "\"%s\"" % self.value195class NTLMSSP_SET(VALUE_TYPE):196 def __init__(self, value: str):197 if "and" in value.split(" "):198 val1, val2 = tuple(map(lambda x: x.capitalize() ,value.lower().split(" and ")))199 if self._validate(val1) and self._validate(val2):200 self.value = "\"%s\" && \"%s\"" % (val1, val2)201 else:202 raise TypeError("%s is not a valid value for NTLMSSP_SET" % str(value))203 elif self._validate(value):204 self.value = value205 else:206 raise TypeError("%s is not a valid value for NTLMSSP_SET" % str(value))207 def _validate(self, value: str) -> bool:208 return value in ("No minimum", "Require message integrity", "Require message confidentiality", "Require ntlmv2 session security", "Require 128-bit encryption")209 210 def __repr__(self) -> str:211 if " && " in self.value:212 return self.value213 else:214 return "\"%s\"" % self.value215class CRYPTO_SET(VALUE_TYPE):216 def __init__(self, value: str):217 if self._validate(value):218 self.value = value219 else:220 raise TypeError("%s is not a valid value for CRYPTO_SET" % str(value))221 def _validate(self, value: str) -> bool:222 return value in ("User input is not required when new keys are stored and used", "User is prompted when the key is first used", "User must enter a password each time they use a key")223 224 def __repr__(self) -> str:225 return "\"%s\"" % self.value226class OBJECT_SET(VALUE_TYPE):227 228 def __init__(self, value: str):229 if self._validate(value):230 self.value = value231 else:232 raise TypeError("%s is not a valid value for OBJECT_SET" % str(value))233 def _validate(self, value: str) -> bool:234 return value in ("Administrators group", "Object creator")235 def __repr__(self) -> str:236 return "\"%s\"" % self.value237class DASD_SET(VALUE_TYPE):238 def __init__(self, value: str):239 if self._validate(value):240 self.value = value241 else:242 raise TypeError("%s is not a valid value for DASD_SET" % str(value))243 def _validate(self, value: str) -> bool:244 return value in ("Administrators", "administrators and power users", "Administrators and interactive users")245 246 def __repr__(self) -> str:247 return "\"%s\"" % self.value248class LANMAN_SET(VALUE_TYPE):249 def __init__(self, value: str):250 value = value.replace(". ", "\\").lower()251 if self._validate(value):252 self.value = value253 else:254 raise TypeError("%s is not a valid value for LANMAN_SET" % str(value))255 def _validate(self, value: str) -> bool:256 return value in ("Send LM & NTLM responses", "send lm & ntlm - use ntlmv2 session security if negotiated", "send ntlm response only", "send ntlmv2 response only", "send ntlmv2 response only\\refuse lm", "send ntlmv2 response only\\refuse lm & ntlm")257 258 def __repr__(self) -> str:259 return "\"%s\"" % self.value260class LDAPCLIENT_SET(VALUE_TYPE):261 def __init__(self, value: str):262 value = value.title()263 if self._validate(value):264 self.value = value265 else:266 raise TypeError("%s is not a valid value for LDAPCLIENT_SET" % str(value))267 def _validate(self, value: str) -> bool:268 return value in ("None", "Negotiate Signing", "Require Signing")269 270 def __repr__(self) -> str:271 return "\"%s\"" % self.value272class EVENT_MEATHOD(VALUE_TYPE):273 def __init__(self, value: str):274 if self._validate(value):275 self.value = value276 else:277 raise TypeError("%s is not a valid value for EVENT_MEATHOD" % str(value))278 def _validate(self, value: str) -> bool:279 return value in ("by days", "manually", "as needed")280 281 def __repr__(self) -> str:282 return "\"%s\"" % self.value 283class POLICY_DAY(POLICY_DWORD):284 def __init__(self, value:DWORD):285 super().__init__(value)286class POLICY_KBYTE(POLICY_DWORD):287 def __init__(self, value:DWORD):288 super().__init__(value)289class ADMIN_PROMPT_SET(VALUE_TYPE):290 291 def __init__(self, value: str):292 if self._validate(value):293 self.value = value294 else:295 raise TypeError("%s is not a valid value for PROMPT_POLICY_SET" % str(value))296 def convert_to_DWORD(self) -> DWORD:297 return DWORD(("Elevate without prompting", "Prompt for credentials on the secure desktop", "Prompt for consent on the secure desktop", "Prompt for credentials", "Prompt for consent", "Prompt for consent for non-Windows binaries").index(self.value))298 def _validate(self, value: str) -> bool:299 return value in ("Elevate without prompting", "Prompt for credentials on the secure desktop", "Prompt for consent on the secure desktop", "Prompt for credentials", "Prompt for consent", "Prompt for consent for non-Windows binaries")300 301 def __repr__(self) -> str:302 return "\"%s\"" % self.value 303class SU_PROMPT_SET(VALUE_TYPE):304 def __init__(self, value: str):305 if self._validate(value):306 self.value = value307 else:308 raise TypeError("%s is not a valid value for PROMPT_POLICY_SET" % str(value))309 def convert_to_DWORD(self) -> DWORD:310 return DWORD(("Automatically deny elevation requests", "Prompt for credentials on the secure desktop", "Prompt for credentials").index(self.value))311 def _validate(self, value: str) -> bool:312 return value in ("Automatically deny elevation requests", "Prompt for credentials on the secure desktop", "Prompt for credentials")313 def __repr__(self) -> str:314 return "\"%s\"" % self.value315class INTERNET_ZONE_SET(VALUE_TYPE):316 def __init__(self, value:str):317 if self._validate(value):318 self.value = value319 else:320 raise TypeError("%s is not a valid value for INTERNET_ZONE_SET" % str(value))321 def convert_to_DWORD(self) -> DWORD:322 return DWORD(("Enable", "Disable", "Prompt").index(self.value))323 324 def _validate(self, value:str) -> bool:325 return value in ("Enable", "Disable", "Prompt")326 def __repr__(self) -> str:327 return "\"%s\"" % self.value328class JAVA_PERMISSIONS_SET(VALUE_TYPE):329 def __init__(self, value:str):330 value = value.title()331 if self._validate(value):332 self.value = value333 else:334 raise TypeError("%s is not a valid value for JAVA_PERMISSIONS_SET" % str(value))335 def convert_to_DWORD(self) -> DWORD:336 return DWORD({"High Safety" : 65536, 337 "Medium Safety" : 131072, 338 "Low Safety" : 196608, 339 "Custom" : 8388608, 340 "Disable Java" : 0}[self.value])341 def _validate(self, value:str) -> bool:342 return value in ("High Safety", "Medium Safety", "Low Safety", "Custom", "Disable Java")343 def __repr__(self) -> str:344 return "\"%s\"" % self.value345class DMA_SET(VALUE_TYPE):346 def __init__(self, value:str):347 value = value.capitalize()348 if self._validate(value):349 self.value = value350 else:351 raise TypeError("%s is not a valid value for DMA_SET" % str(value))352 def convert_to_DWORD(self) -> DWORD:353 return DWORD(("Block all", "Only while logged in", "Allow all").index(self.value))354 355 def _validate(self, value:str) -> bool:356 return value in ("Block all", "Only while logged in", "Allow all")357 def __repr__(self) -> str:358 return "\"%s\"" % self.value359class SSL_FALLBACK(VALUE_TYPE):360 def __init__(self, value:str):361 value = value.title()362 if self._validate(value):363 self.value = value364 else:365 raise TypeError("%s is not a valid value for SSL_FALLBACK" % str(value))366 367 def convert_to_DWORD(self) -> DWORD:368 return DWORD(("No Sites", "Non-Protected Mode Sites", "All Sites").index(self.value))369 def _validate(self, value) -> bool:370 return value in ("No Sites", "Non-Protected Mode Sites", "All Sites")371 372 def __repr__(self) ->str:373 return "\"%s\"" % self.value374class DEFENDER_SET(VALUE_TYPE):375 def __init__(self, value:str):376 value = value.title()377 if self._validate(value):378 self.value = value379 else:380 raise TypeError("%s is not a valid value for DEFENDER_SET" % str(value))381 def convert_to_DWORD(self) -> DWORD:382 return DWORD(("Disable (Default)","Block", "Audit Mode").index(self.value))383 def _validate(self, value:str) -> bool:384 return value in ("Disable (Default)","Block", "Audit Mode")385 def __repr__(self)->str:386 return "\"%s\"" % self.value387class SMB_DRIVER(VALUE_TYPE):388 def __init__(self, value:str):389 value = value.capitalize()390 if self._validate(value):391 self.value = value392 else:393 raise TypeError("%s is not a valid value for SMB_DRIVER" % str(value))394 def convert_to_DWORD(self) -> DWORD:395 return DWORD({"Disable driver":4,396 "Manual start":3, 397 "Automatic start":2}[self.value])398 def _validate(self, value:str) -> bool:399 return value in ("Disable driver","Manual start", "Automatic start")400 def __repr__(self)->str:401 return "\"%s\"" % self.value402class ORACLE_REMEDIATION(VALUE_TYPE):403 def __init__(self, value:str):404 value = value.title()405 if self._validate(value):406 self.value = value407 else:408 raise TypeError("%s is not a valid value for ORACLE_REMEDIATION" % str(value))409 def convert_to_DWORD(self) -> DWORD:410 return DWORD(("Force Updated Clients","Mitigated","Vulnerable").index(self.value))411 def _validate(self, value: str) -> bool:412 return value in ("Force Updated Clients","Mitigated","Vulnerable")413 414 def __repr__(self)->str:415 return "\"%s\"" % self.value416class JOIN_MAPS(VALUE_TYPE):417 def __init__(self, value:str):418 if self._validate(value):419 self.value = value420 else:421 raise TypeError("%s is not a valid value for JOIN_MAPS" % str(value))422 def convert_to_DWORD(self) -> DWORD:423 return DWORD(("Disabled", "Basic MAPS", "Advanced MAPS").index(self.value))424 def _validate(self, value: str) -> bool:425 return value in ("Disabled", "Basic MAPS", "Advanced MAPS")426 427 def __repr__(self)->str:428 return "\"%s\"" % self.value429class SERVICE_SET(VALUE_TYPE):430 value_type = "SERVICE_SET"431 def __init__(self, value:str):432 if self._validate(value):433 self.value = value434 else:435 raise TypeError("%s is not a valid value for SERVICE_SET" % str(value))436 437 def convert_to_DWORD(self) -> DWORD:438 return DWORD(("Automatic", "Manual", "Disabled").index(self.value))439 def _validate(self, value) -> bool:440 return value in ("Automatic", "Manual", "Disabled")441 def __repr__(self) -> str:442 return "\"%s\"" % self.value443convertable_type_list = (444 DWORD,445 POLICY_SET,446 ADMIN_PROMPT_SET,447 SU_PROMPT_SET,448 INTERNET_ZONE_SET,449 JAVA_PERMISSIONS_SET,450 DMA_SET,451 SSL_FALLBACK,452 DEFENDER_SET,453 SMB_DRIVER,...
generated_validators.py
Source:generated_validators.py
1@validate.command()2@click.option('--trace', default="")3def edu_exercises(trace):4 """5 List files containing unincorporated EDU exercises6 """7 click.echo(_validate.Validator.one_check(_validate.ExerciseForEDU, trace))8@validate.command()9@click.option('--trace', default="")10def tabs(trace):11 """12 There shouldn't be tabs13 """14 click.echo(_validate.Validator.one_check(_validate.NoTabs, trace))15@validate.command()16@click.option('--trace', default="")17def bad_chars(trace):18 """19 Find bad characters20 """21 click.echo(_validate.Validator.one_check(_validate.Characters, trace))22@validate.command()23@click.option('--trace', default="")24def backtick_gap(trace):25 """26 No gap between ``` and language_name27 """28 click.echo(_validate.Validator.one_check(_validate.TagNoGap, trace))29@validate.command()30@click.option('--trace', default="")31def titles(trace):32 """33 Atom titles should conform to standard and agree with file names34 """35 click.echo(_validate.Validator.one_check(_validate.FilenamesAndTitles, trace))36@validate.command()37@click.option('--trace', default="")38def package_names(trace):39 """40 Package names shouldn't have capital letters41 """42 click.echo(_validate.Validator.one_check(_validate.PackageNames, trace))43@validate.command()44@click.option('--trace', default="")45def hotwords(trace):46 """47 Words that might need rewriting48 """49 click.echo(_validate.Validator.one_check(_validate.HotWords, trace))50@validate.command()51@click.option('--trace', default="")52def listing_width(trace):53 """54 Code listings shouldn't exceed line widths55 """56 click.echo(_validate.Validator.one_check(_validate.CodeListingLineWidths, trace))57@validate.command()58@click.option('--trace', default="")59def sluglines(trace):60 """61 Sluglines should match the format62 """63 click.echo(_validate.Validator.one_check(_validate.ExampleSluglines, trace))64@validate.command()65@click.option('--trace', default="")66def complete_examples(trace):67 """68 Find code fragments that should be turned into examples69 """70 click.echo(_validate.Validator.one_check(_validate.CompleteExamples, trace))71@validate.command()72@click.option('--trace', default="")73def spelling(trace):74 """75 Spell-check everything76 """77 click.echo(_validate.Validator.one_check(_validate.SpellCheck, trace))78@validate.command()79@click.option('--trace', default="")80def hanging_hyphens(trace):81 """82 No hanging em-dashes or hyphens83 """84 click.echo(_validate.Validator.one_check(_validate.HangingHyphens, trace))85@validate.command()86@click.option('--trace', default="")87def function_descriptions(trace):88 """89 Functions in prose should use parentheses90 """91 click.echo(_validate.Validator.one_check(_validate.FunctionDescriptions, trace))92@validate.command()93@click.option('--trace', default="")94def println_output(trace):95 """96 println() should have /* Output:97 """98 click.echo(_validate.Validator.one_check(_validate.PrintlnOutput, trace))99@validate.command()100@click.option('--trace', default="")101def comment_capitalization(trace):102 """103 Comments should be capitalized104 """105 click.echo(_validate.Validator.one_check(_validate.CapitalizedComments, trace))106@validate.command()107@click.option('--trace', default="")108def listing_indentation(trace):109 """110 Indentation should be consistent111 """112 click.echo(_validate.Validator.one_check(_validate.ListingIndentation, trace))113@validate.command()114@click.option('--trace', default="")115def ticked_words(trace):116 """117 Spell-check single-ticked items against compiled code118 """119 click.echo(_validate.Validator.one_check(_validate.TickedWords, trace))120@validate.command()121@click.option('--trace', default="")122def cross_links(trace):123 """124 Find invalid cross-links125 """126 click.echo(_validate.Validator.one_check(_validate.CrossLinks, trace))127@validate.command()128@click.option('--trace', default="")129def mistaken_backquotes(trace):130 """131 Discover when backquotes are messed up by paragraph reformatting132 """133 click.echo(_validate.Validator.one_check(_validate.MistakenBackquotes, trace))134@validate.command()135@click.option('--trace', default="")136def java_packages(trace):137 """138 Directory names for atoms that contain Java examples must be lowercase.139 """140 click.echo(_validate.Validator.one_check(_validate.JavaPackageDirectory, trace))141@validate.command()142@click.option('--trace', default="")143def blank_lines(trace):144 """145 Make sure there isn't more than a single blank line anywhere,146 and that there's a single blank line before/after the end of a code listing.147 """148 click.echo(_validate.Validator.one_check(_validate.CheckBlankLines, trace))149@validate.command()150@click.option('--trace', default="")151def duplicate_example_names(trace):152 """153 Example names can't be duplicated154 """155 click.echo(_validate.Validator.one_check(_validate.DuplicateExampleNames, trace))156@validate.command()157@click.option('--trace', default="")158def package_and_directory_names(trace):159 """160 Package names should be consistent with directory names161 """162 click.echo(_validate.Validator.one_check(_validate.PackageAndDirectoryNames, trace))163@validate.command()164@click.option('--trace', default="")165def directory_name_consistency(trace):166 """167 Directory names in sluglines should be consistent with atom names168 """...
test_uri.py
Source:test_uri.py
...5class TestUriMethods(unittest.TestCase):6 def test_validate_charset_fail_1(self):7 self.assertRaises(ValueError, _validate, 'charset', '.')8 def test_validate_charset_pass_1(self):9 value = _validate('charset', 'utf8')10 self.assertEqual(value, 'utf8')11 def test_validate_charset_pass_2(self):12 value = _validate('charset', 'utf8mb3')13 self.assertEqual(value, 'utf8mb3')14 def test_validate_charset_pass_3(self):15 value = _validate('charset', 'utf8mb4')16 self.assertEqual(value, 'utf8mb4')17 def test_validate_dialect_fail_1(self):18 self.assertRaises(ValueError, _validate, 'dialect', '.')19 def test_validate_dialect_fail_2(self):20 self.assertRaises(ValueError, _validate, 'dialect', '$mysql')21 def test_validate_dialect_fail_3(self):22 self.assertRaises(ValueError, _validate, 'dialect', 'mysql+')23 def test_validate_dialect_pass_1(self):24 value = _validate('dialect', 'mysql')25 self.assertEqual(value, 'mysql')26 def test_validate_dialect_pass_1(self):27 value = _validate('dialect', 'sqlite')28 self.assertEqual(value, 'sqlite')29 def test_validate_driver_fail_1(self):30 self.assertRaises(ValueError, _validate, 'driver', '.')31 def test_validate_driver_pass_1(self):32 value = _validate('driver', 'pymysql')33 self.assertEqual(value, 'pymysql')34 def test_validate_driver_pass_1(self):35 value = _validate('driver', 'psycopg2')36 self.assertEqual(value, 'psycopg2')37 def test_validate_host_fail_1(self):38 self.assertRaises(ValueError, _validate, 'host', '')39 def test_validate_host_fail_2(self):40 self.assertRaises(ValueError, _validate, 'host', '.')41 def test_validate_host_fail_3(self):42 self.assertRaises(ValueError, _validate, 'host', '123abc')43 def test_validate_host_pass_1(self):44 value = _validate('host', '127.0.0.1')45 self.assertEqual(value, '127.0.0.1')46 def test_validate_host_pass_2(self):47 value = _validate('host', 'localhost')48 self.assertEqual(value, 'localhost')49 def test_validate_host_fail_4(self):50 value = _validate('host', 'localhost.localdomain')51 self.assertEqual(value, 'localhost.localdomain')52 def test_validate_pathname_fail_1(self):53 self.assertRaises(ValueError, _validate, 'pathname', '.')54 def test_validate_pathname_fail_2(self):55 self.assertRaises(ValueError, _validate, 'pathname', '..')56 def test_validate_pathname_fail_3(self):57 self.assertRaises(ValueError, _validate, 'pathname', 'foo.')58 def test_validate_pathname_fail_4(self):59 self.assertRaises(ValueError, _validate, 'pathname', '.foo.')60 def test_validate_pathname_pass_1(self):61 value = _validate('pathname', 'foo')62 self.assertEqual(value, 'foo')63 def test_validate_pathname_pass_2(self):64 value = _validate('pathname', '.foo')65 self.assertEqual(value, '.foo')66 def test_validate_pathname_pass_3(self):67 value = _validate('pathname', 'foo-bar')68 self.assertEqual(value, 'foo-bar')69 def test_validate_pathname_pass_4(self):70 value = _validate('pathname', 'foo-bar.sqlite')71 self.assertEqual(value, 'foo-bar.sqlite')72 def test_validate_pathname_pass_5(self):73 value = _validate('pathname', '/tmp/foo-bar.sqlite')74 self.assertEqual(value, '/tmp/foo-bar.sqlite')75 def test_validate_pathname_pass_6(self):76 value = _validate('pathname', '/home/jdoe/foo-bar.sqlite')77 self.assertEqual(value, '/home/jdoe/foo-bar.sqlite')78 def test_validate_password_fail_1(self):79 self.assertRaises(ValueError, _validate, 'password', '')80 def test_validate_password_pass_1(self):81 password = '!@#$%^&*()-=_+[]{}|;:,./<>?'82 value = _validate('password', password)83 self.assertEqual(value, password)84 def test_validate_port_fail_1(self):85 self.assertRaises(ValueError, _validate, 'port', '100000')86 def test_validate_port_pass_1(self):87 value = _validate('port', '3306')88 self.assertEqual(value, '3306')89 def test_validate_user_fail_1(self):90 self.assertRaises(ValueError, _validate, 'user', '.')91 def test_validate_user_fail_2(self):92 self.assertRaises(ValueError, _validate, 'user', 'root:')93 def test_validate_user_fail_3(self):94 self.assertRaises(ValueError, _validate, 'user', 'root@')95 def test_validate_user_pass_1(self):96 value = _validate('user', 'root')97 self.assertEqual(value, 'root')98if __name__ == '__main__':...
engine_test.py
Source:engine_test.py
...6 """7 An adverb8 """9 (semantic, syntax) = Engine(datetime(2021, 1, 1).date()).when("Aujourd'hui")10 self._validate([date(2021, 1, 1)], semantic)11 self._validate(['adverb(French)'], syntax)12 def test_single_abbreviated_week_day_and_month_utf_8(self):13 """14 Single explicit week day and month using UTF-815 """16 semantic, syntax = Engine(datetime(2021, 4, 27).date()).when('7 PAŹ')17 self._validate([date(2021, 10, 7)], semantic)18 self._validate(['dm(abbreviated(Polish))'], syntax)19 def test_single_explicit_week_day_and_month(self):20 """21 Single explicit week day and month22 """23 semantic, syntax = Engine(datetime(2021, 4, 27).date()).when('Tisdag, 18 Maj')24 self._validate([date(2021, 5, 18)], semantic)25 self._validate(['sd(wd(Swedish), dm(explicit(Danish)))'], syntax)26 def test_single_explicit_week_day_and_day_dot(self):27 """28 Single explicit week day and day dot29 """30 semantic, syntax = Engine(datetime(2021, 4, 27).date()).when('Freitag, 7. Mai')31 self._validate([date(2021, 5, 7)], semantic)32 self._validate(['sd(wd(German), dm(explicit(French)))'], syntax)33 def test_explicit_post_fixed_months_and_abbreviations(self):34 """35 Explicit post-fixed months and abbreviations36 """37 (semantic, syntax) = Engine(datetime(2021, 4, 27).date()).when('28. Aug. - 1. Sept.')38 self._validate([date(2021, 8, 28), date(2021, 9, 1)], semantic)39 self._validate(['dm(abbreviated(Danish))', 'dm(abbreviated(Danish))'], syntax)40 def test_explicit_post_fixed_months_without_abbreviations(self):41 """42 Explicit post-fixed months without abbreviations43 """44 (semantic, syntax) = Engine(datetime(2021, 4, 27).date()).when('21 Juin - 9 Juil.')45 self._validate([date(2021, 6, 21), date(2021, 7, 9)], semantic)46 self._validate(['dm(explicit(French))', 'dm(abbreviated(French))'], syntax)47 def test_implicit_start_month_and_abbreviated_end(self):48 """49 Implicit start month and abbreviated end50 """51 semantic, syntax = Engine(datetime(2021, 4, 27).date()).when('12. - 14. Aug.')52 self._validate([date(2021, 5, 12), date(2021, 8, 14)], semantic)53 self._validate(['d(unknown)', 'dm(abbreviated(Danish))'], syntax)54 def test_implicit_start_month_and_post_fixed_explicit_end(self):55 """56 Implicit start month and post-fixed explicit end57 """58 semantic, syntax = Engine(datetime(2021, 4, 27).date()).when('12 - 14 Mai')59 self._validate([date(2021, 5, 12), date(2021, 5, 14)], semantic)60 self._validate(['d(unknown)', 'dm(explicit(French))'], syntax)61 def test_post_fixed_start_month_and_implicit_end(self):62 """63 Post-fixed start month and implicit end64 """65 semantic, syntax = Engine(datetime(2021, 4, 27).date()).when('21 Juin - 9')66 self._validate([date(2021, 6, 21), date(2021, 7, 9)], semantic)67 self._validate(['dm(explicit(French))', 'd(unknown)'], syntax)68 # Time Machine Tests69 def test_present_prefixed_start_month_and_implicit_end(self):70 """71 Prefixed start month and implicit end72 """73 (semantic, syntax) = Engine(datetime(2021, 5, 6).date()).when('Maj 6 - 14')74 self._validate([date(2021, 5, 6), date(2021, 5, 14)], semantic)75 self._validate(['md(explicit(Danish))', 'd(unknown)'], syntax)76 def test_future_prefixed_start_month_and_implicit_end(self):77 """78 Prefixed start month and implicit end79 """80 (semantic, syntax) = Engine(datetime(2021, 5, 5).date()).when('Maj 6 - 14')81 self._validate([date(2021, 5, 6), date(2021, 5, 14)], semantic)82 self._validate(['md(explicit(Danish))', 'd(unknown)'], syntax)83 def test_past_prefixed_start_month_and_implicit_end(self):84 """85 Past prefixed start month and implicit end86 """87 (semantic, syntax) = Engine(datetime(2021, 4, 27).date()).when('Januari 1 - 14')88 self._validate([date(2022, 1, 1), date(2022, 1, 14)], semantic)89 self._validate(['md(explicit(Dutch))', 'd(unknown)'], syntax)90 def _validate(self, expected, actual):...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!