Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Commit

Permalink
Merge branch 'improve_scheme_re'
Browse files Browse the repository at this point in the history
  • Loading branch information
rockymeza committed Mar 10, 2016
2 parents ffd2e39 + 6d4c7a7 commit 77c3f08
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
17 changes: 16 additions & 1 deletion tests/test_schemes.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@
iface wlan0-coffee2 inet dhcp
wireless-essid Coffee 2
wireless-channel auto
iface wlan0-with-hyphen inet dhcp
wireless-channel auto
wireless-essid with-hyphen
iface xyz1-scheme inet dhcp
wireless-channel auto
wireless-essid scheme
"""


Expand All @@ -52,14 +60,21 @@ def tearDown(self):
os.remove(self.Scheme.interfaces)

def test_scheme_extraction(self):
work, coffee, home, coffee2 = extract_schemes(NETWORK_INTERFACES_FILE)
work, coffee, home, coffee2 = list(extract_schemes(NETWORK_INTERFACES_FILE))[:4]

assert work.name == 'work'
assert work.options['wpa-ssid'] == 'workwifi'

assert coffee.name == 'coffee'
assert coffee.options['wireless-essid'] == 'Coffee WiFi'

def test_with_hyphen(self):
with_hyphen = self.Scheme.find('wlan0', 'with-hyphen')
assert with_hyphen.options['wireless-essid'] == 'with-hyphen'

def test_with_different_interface(self):
assert self.Scheme.find('xyz1', 'scheme')

def test_str(self):
scheme = self.Scheme('wlan0', 'test')
assert str(scheme) == 'iface wlan0-test inet dhcp\n'
Expand Down
3 changes: 1 addition & 2 deletions wifi/scheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,7 @@ def __init__(self, scheme, ip_address):
self.ip_address = ip_address


# TODO: support other interfaces
scheme_re = re.compile(r'iface\s+(?P<interface>wlan\d?)(?:-(?P<name>\w+))?')
scheme_re = re.compile(r'iface\s+(?P<interface>[^-]+)(?:-(?P<name>\S+))?')


def extract_schemes(interfaces, scheme_class=Scheme):
Expand Down

0 comments on commit 77c3f08

Please sign in to comment.