Skip to content

Commit

Permalink
python: use raw strings for regexp patterns
Browse files Browse the repository at this point in the history
Behaviour is not changed, because "unknown" escapes like \s or \d were not
substituted, but it's much nicer to use raw strings to avoid ambiguity.
  • Loading branch information
keszybz committed Dec 2, 2016
1 parent 8d9d1e3 commit cda3997
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
24 changes: 12 additions & 12 deletions test/networkd-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,30 +166,30 @@ def do_test(self, coldplug=True, ipv6=False, extra_opts='',
else:
# should have link-local address on IPv6 only
out = subprocess.check_output(['ip', '-6', 'a', 'show', 'dev', self.iface])
self.assertRegex(out, b'inet6 fe80::.* scope link')
self.assertRegex(out, br'inet6 fe80::.* scope link')
self.assertNotIn(b'scope global', out)

# should have IPv4 address
out = subprocess.check_output(['ip', '-4', 'a', 'show', 'dev', self.iface])
self.assertIn(b'state UP', out)
self.assertRegex(out, b'inet 192.168.5.\d+/.* scope global dynamic')
self.assertRegex(out, br'inet 192.168.5.\d+/.* scope global dynamic')

# check networkctl state
out = subprocess.check_output(['networkctl'])
self.assertRegex(out, ('%s\s+ether\s+routable\s+unmanaged' % self.if_router).encode())
self.assertRegex(out, ('%s\s+ether\s+routable\s+configured' % self.iface).encode())
self.assertRegex(out, (r'%s\s+ether\s+routable\s+unmanaged' % self.if_router).encode())
self.assertRegex(out, (r'%s\s+ether\s+routable\s+configured' % self.iface).encode())

out = subprocess.check_output(['networkctl', 'status', self.iface])
self.assertRegex(out, b'Type:\s+ether')
self.assertRegex(out, b'State:\s+routable.*configured')
self.assertRegex(out, b'Address:\s+192.168.5.\d+')
self.assertRegex(out, br'Type:\s+ether')
self.assertRegex(out, br'State:\s+routable.*configured')
self.assertRegex(out, br'Address:\s+192.168.5.\d+')
if ipv6:
self.assertRegex(out, b'2600::')
self.assertRegex(out, br'2600::')
else:
self.assertNotIn(b'2600::', out)
self.assertRegex(out, b'fe80::')
self.assertRegex(out, b'Gateway:\s+192.168.5.1')
self.assertRegex(out, b'DNS:\s+192.168.5.1')
self.assertNotIn(br'2600::', out)
self.assertRegex(out, br'fe80::')
self.assertRegex(out, br'Gateway:\s+192.168.5.1')
self.assertRegex(out, br'DNS:\s+192.168.5.1')
except (AssertionError, subprocess.CalledProcessError):
# show networkd status, journal, and DHCP server log on failure
with open(self.config) as f:
Expand Down
8 changes: 4 additions & 4 deletions test/rule-syntax-check.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
sys.exit(2)
rules_files = glob(os.path.join(rules_dir, '*.rules'))

no_args_tests = re.compile('(ACTION|DEVPATH|KERNELS?|NAME|SYMLINK|SUBSYSTEMS?|DRIVERS?|TAG|RESULT|TEST)\s*(?:=|!)=\s*"([^"]*)"$')
args_tests = re.compile('(ATTRS?|ENV|TEST){([a-zA-Z0-9/_.*%-]+)}\s*(?:=|!)=\s*"([^"]*)"$')
no_args_assign = re.compile('(NAME|SYMLINK|OWNER|GROUP|MODE|TAG|PROGRAM|RUN|LABEL|GOTO|OPTIONS|IMPORT)\s*(?:\+=|:=|=)\s*"([^"]*)"$')
args_assign = re.compile('(ATTR|ENV|IMPORT|RUN){([a-zA-Z0-9/_.*%-]+)}\s*(=|\+=)\s*"([^"]*)"$')
no_args_tests = re.compile(r'(ACTION|DEVPATH|KERNELS?|NAME|SYMLINK|SUBSYSTEMS?|DRIVERS?|TAG|RESULT|TEST)\s*(?:=|!)=\s*"([^"]*)"$')
args_tests = re.compile(r'(ATTRS?|ENV|TEST){([a-zA-Z0-9/_.*%-]+)}\s*(?:=|!)=\s*"([^"]*)"$')
no_args_assign = re.compile(r'(NAME|SYMLINK|OWNER|GROUP|MODE|TAG|PROGRAM|RUN|LABEL|GOTO|OPTIONS|IMPORT)\s*(?:\+=|:=|=)\s*"([^"]*)"$')
args_assign = re.compile(r'(ATTR|ENV|IMPORT|RUN){([a-zA-Z0-9/_.*%-]+)}\s*(=|\+=)\s*"([^"]*)"$')

result = 0
buffer = ''
Expand Down

0 comments on commit cda3997

Please sign in to comment.