1+ import re
12import sys
23from os import path
34from unittest import TestCase
@@ -21,7 +22,24 @@ def setUpClass(cls):
2122 def assert_cli_exception (self , args , message ):
2223 result = self .runner .invoke (cli , args , standalone_mode = False )
2324 self .assertIsInstance (result .exception , CliError )
24- assert getattr (result .exception , "message" ) == message
25+
26+ if isinstance (message , str ):
27+ message = [message ]
28+
29+ for part in message :
30+
31+ # Test if the string is a regex
32+ is_regex = False
33+ try :
34+ re .compile (part )
35+ is_regex = True
36+ except re .error :
37+ pass
38+
39+ if is_regex :
40+ assert re .search (part , result .exception .message , re .MULTILINE )
41+ else :
42+ assert part == result .exception .message
2543
2644 def test_bad_deploy_file (self ):
2745 self .assert_cli_exception (
@@ -44,13 +62,12 @@ def test_no_fact_module(self):
4462 def test_no_fact_cls (self ):
4563 self .assert_cli_exception (
4664 ["my-server.net" , "fact" , "server.NotAFact" ],
47- (
48- "No such attribute in module server: NotAFact\n "
49- "Available facts in module are: User, Home, Path, TmpDir, Hostname, Kernel, "
50- "KernelVersion, Os, OsVersion, Arch, Command, Which, Date, MacosVersion, Mounts, "
51- "KernelModules, LsbRelease, OsRelease, Sysctl, Groups, Users, LinuxDistribution, "
52- "Selinux, LinuxGui, Locales, SecurityLimits"
53- ),
65+ [
66+ r"^No such attribute in module server: NotAFact.*" ,
67+ r".*Available facts are: .*" ,
68+ r".* User,.*" ,
69+ r".* Os," ,
70+ ],
5471 )
5572
5673
0 commit comments