Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Cyborg)
  • No Skin
Collapse
Brand Logo

CIRCLE WITH A DOT

  1. Home
  2. Uncategorized
  3. I have a question about Python libraries and testing scope.

I have a question about Python libraries and testing scope.

Scheduled Pinned Locked Moved Uncategorized
pythonunittesttestingsensors
1 Posts 1 Posters 6 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • mjack@mastodon.bsd.cafeM This user is from outside of this forum
    mjack@mastodon.bsd.cafeM This user is from outside of this forum
    mjack@mastodon.bsd.cafe
    wrote last edited by
    #1

    I have a question about Python libraries and testing scope.

    If I'm importing 'serial' in my library, and use it like the following to create a connection to a sensor:

    --- start code ---

    import serial

    class Sensor:
    def __init__(self, serial_device):

    self.__serial_device = serial_device

    try:
    self.__connection = serial.Serial(
    port=serial_device,
    baudrate=9600,
    bytesize=serial.EIGHTBITS,
    parity=serial.PARITY_NONE,
    stopbits=serial.STOPBITS_ONE,
    )

    except serial.SerialException:
    print("Could not establish serial connection to sensor")

    --- end code ---

    how much testing should I do around the serial connection? Just mock up a few buffers (byte streams), and see how my class handles unexpected input?

    One the one hand, I want to make the library as solid as possible. On the other hand, I don't want to run tests on code I don't control (the library module). I know of the 'mock-serial' utility, but haven't used it.

    The aim is to make a Python version of my Arduino library for the CozIR Ambient CO2 sensor:

    https://codeberg.org/mjack/ambientCO2/src/branch/develop

    #python #unittest #testing #sensors

    1 Reply Last reply
    1
    0
    • stefano@mastodon.bsd.cafeS stefano@mastodon.bsd.cafe shared this topic
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups