1
+ import re
1
2
import sys
2
3
from os import path
3
4
from unittest import TestCase
@@ -21,7 +22,24 @@ def setUpClass(cls):
21
22
def assert_cli_exception (self , args , message ):
22
23
result = self .runner .invoke (cli , args , standalone_mode = False )
23
24
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
25
43
26
44
def test_bad_deploy_file (self ):
27
45
self .assert_cli_exception (
@@ -44,13 +62,12 @@ def test_no_fact_module(self):
44
62
def test_no_fact_cls (self ):
45
63
self .assert_cli_exception (
46
64
["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
+ ],
54
71
)
55
72
56
73
0 commit comments