[PATCH] osmo-gsm-tester[master]: Move Sms class to a separate module

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Pau Espin Pedrol gerrit-no-reply at lists.osmocom.org
Tue May 30 13:40:52 UTC 2017


Hello Jenkins Builder,

I'd like you to reexamine a change.  Please visit

    https://gerrit.osmocom.org/2796

to look at the new patch set (#2).

Move Sms class to a separate module

Preparation for following commits to add smpp support, as we will have a
class SmppClient with a method accepting an Sms object to send it.

Change-Id: I1f28e14e963abb64df687b69d54975be2aeb0d0d
---
M selftest/sms_test.py
M src/osmo_gsm_tester/ofono_client.py
A src/osmo_gsm_tester/sms.py
3 files changed, 77 insertions(+), 47 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-gsm-tester refs/changes/96/2796/2

diff --git a/selftest/sms_test.py b/selftest/sms_test.py
index 25fb551..ce81c3e 100755
--- a/selftest/sms_test.py
+++ b/selftest/sms_test.py
@@ -1,20 +1,20 @@
 #!/usr/bin/env python3
 
 import _prep
-from osmo_gsm_tester import ofono_client
+from osmo_gsm_tester import sms
 
-print(ofono_client.Sms())
-print(ofono_client.Sms())
-print(ofono_client.Sms())
-sms = ofono_client.Sms('123', '456')
-print(str(sms))
+print(sms.Sms())
+print(sms.Sms())
+print(sms.Sms())
+msg = sms.Sms('123', '456')
+print(str(msg))
 
-sms2 = ofono_client.Sms('123', '456')
-print(str(sms2))
-assert sms != sms2
+msg2 = sms.Sms('123', '456')
+print(str(msg2))
+assert msg != msg2
 
-sms2.msg = str(sms.msg)
-print(str(sms2))
-assert sms == sms2
+msg2.msg = str(msg.msg)
+print(str(msg2))
+assert msg == msg2
 
 # vim: expandtab tabstop=4 shiftwidth=4
diff --git a/src/osmo_gsm_tester/ofono_client.py b/src/osmo_gsm_tester/ofono_client.py
index ce937d0..ef52a29 100644
--- a/src/osmo_gsm_tester/ofono_client.py
+++ b/src/osmo_gsm_tester/ofono_client.py
@@ -17,7 +17,7 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-from . import log, test, util, event_loop
+from . import log, test, util, event_loop, sms
 
 from pydbus import SystemBus, Variant
 import time
@@ -347,51 +347,23 @@
             tokens.append('to ' + to_msisdn_or_modem.name())
         else:
             to_msisdn = str(to_msisdn_or_modem)
-        sms = Sms(self.msisdn, to_msisdn, 'from ' + self.name(), *tokens)
-        self.log('sending sms to MSISDN', to_msisdn, sms=sms)
+        msg = sms.Sms(self.msisdn, to_msisdn, 'from ' + self.name(), *tokens)
+        self.log('sending sms to MSISDN', to_msisdn, sms=msg)
         mm = self.dbus.interface(I_SMS)
-        mm.SendMessage(to_msisdn, str(sms))
-        return sms
+        mm.SendMessage(to_msisdn, str(msg))
+        return msg
 
     def _on_incoming_message(self, message, info):
         self.log('Incoming SMS:', repr(message))
         self.dbg(info=info)
         self.sms_received_list.append((message, info))
 
-    def sms_was_received(self, sms):
+    def sms_was_received(self, sms_obj):
         for msg, info in self.sms_received_list:
-            if sms.matches(msg):
+            if sms_obj.matches(msg):
                 self.log('SMS received as expected:', repr(msg))
                 self.dbg(info=info)
                 return True
         return False
-
-class Sms:
-    _last_sms_idx = 0
-    msg = None
-
-    def __init__(self, from_msisdn=None, to_msisdn=None, *tokens):
-        Sms._last_sms_idx += 1
-        msgs = ['message nr. %d' % Sms._last_sms_idx]
-        msgs.extend(tokens)
-        if from_msisdn:
-            msgs.append('from %s' % from_msisdn)
-        if to_msisdn:
-            msgs.append('to %s' % to_msisdn)
-        self.msg = ', '.join(msgs)
-
-    def __str__(self):
-        return self.msg
-
-    def __repr__(self):
-        return repr(self.msg)
-
-    def __eq__(self, other):
-        if isinstance(other, Sms):
-            return self.msg == other.msg
-        return inself.msg == other
-
-    def matches(self, msg):
-        return self.msg == msg
 
 # vim: expandtab tabstop=4 shiftwidth=4
diff --git a/src/osmo_gsm_tester/sms.py b/src/osmo_gsm_tester/sms.py
new file mode 100644
index 0000000..036b64c
--- /dev/null
+++ b/src/osmo_gsm_tester/sms.py
@@ -0,0 +1,58 @@
+# osmo_gsm_tester: DBUS client to talk to ofono
+#
+# Copyright (C) 2016-2017 by sysmocom - s.f.m.c. GmbH
+#
+# Author: Neels Hofmeyr <neels at hofmeyr.de>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+from . import log, test, util, event_loop
+
+class Sms:
+    _last_sms_idx = 0
+    msg = None
+
+    def __init__(self, src_msisdn=None, dst_msisdn=None, *tokens):
+        Sms._last_sms_idx += 1
+        self._src_msisdn = src_msisdn
+        self._dst_msisdn = dst_msisdn
+        msgs = ['message nr. %d' % Sms._last_sms_idx]
+        msgs.extend(tokens)
+        if src_msisdn:
+            msgs.append('from %s' % src_msisdn)
+        if dst_msisdn:
+            msgs.append('to %s' % dst_msisdn)
+        self.msg = ', '.join(msgs)
+
+    def __str__(self):
+        return self.msg
+
+    def __repr__(self):
+        return repr(self.msg)
+
+    def __eq__(self, other):
+        if isinstance(other, Sms):
+            return self.msg == other.msg
+        return inself.msg == other
+
+    def src_msisdn():
+        return self._src_msisdn
+
+    def dst_msisdn():
+        return self._dst_msisdn
+
+    def matches(self, msg):
+        return self.msg == msg
+
+# vim: expandtab tabstop=4 shiftwidth=4

-- 
To view, visit https://gerrit.osmocom.org/2796
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I1f28e14e963abb64df687b69d54975be2aeb0d0d
Gerrit-PatchSet: 2
Gerrit-Project: osmo-gsm-tester
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol <pespin at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder



More information about the gerrit-log mailing list