aboutsummaryrefslogtreecommitdiff
path: root/test/test_context.py
diff options
context:
space:
mode:
authorfrankfeng <frankfeng@google.com>2022-04-12 13:48:48 -0700
committerfrankfeng <frankfeng@google.com>2022-04-12 13:59:52 -0700
commit348b762da3a430415ce1f97e4dd72699cbd14aee (patch)
treeccea6f5053065778e64625fba99e6c03f374812f /test/test_context.py
parent1b7d0d0b6570fe4934000280618db8a92e75bef0 (diff)
parent9e3b4f364aa50bd62d3044ed0d5221bd42a1c1f4 (diff)
downloadpyserial-348b762da3a430415ce1f97e4dd72699cbd14aee.tar.gz
Merge remote-tracking branch 'aosp/upstream-master' into pyserialplatform-tools-33.0.2main-cg-testing-release
Bug: 228235300 Bug: 228457005 Test: TH Change-Id: Ic7c3b0db59780c83ca9bffb2ad4b3dfbea0f8869
Diffstat (limited to 'test/test_context.py')
-rwxr-xr-xtest/test_context.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/test/test_context.py b/test/test_context.py
new file mode 100755
index 0000000..a65a626
--- /dev/null
+++ b/test/test_context.py
@@ -0,0 +1,49 @@
+#! /usr/bin/env python
+#
+# This file is part of pySerial - Cross platform serial port support for Python
+# (C) 2017 Guillaume Galeazzi <guillaume.g@leazzi.ch>
+#
+# SPDX-License-Identifier: BSD-3-Clause
+"""\
+Some tests for the serial module.
+Part of pySerial (http://pyserial.sf.net) (C)2001-2011 cliechti@gmx.net
+
+Intended to be run on different platforms, to ensure portability of
+the code.
+
+Cover some of the aspects of context management
+"""
+
+import unittest
+import serial
+
+# on which port should the tests be performed:
+PORT = 'loop://'
+
+
+class Test_Context(unittest.TestCase):
+ """Test context"""
+
+ def setUp(self):
+ # create a closed serial port
+ self.s = serial.serial_for_url(PORT)
+
+ def tearDown(self):
+ self.s.close()
+
+ def test_with_idempotent(self):
+ with self.s as stream:
+ stream.write(b'1234')
+
+ # do other stuff like calling an exe which use COM4
+
+ with self.s as stream:
+ stream.write(b'5678')
+
+
+if __name__ == '__main__':
+ import sys
+ sys.stdout.write(__doc__)
+ sys.argv[1:] = ['-v']
+ # When this module is executed from the command-line, it runs all its tests
+ unittest.main()