<commit_before>import os
import pytest

from ..utils.indi import PanIndiServer, PanIndiDevice


class TestIndiBasics(object):
    """ Class for testing INDI modules """

    def test_server_create_and_delete(self):
        """ Creates a server with no config, test it is there, delete it and make sure gone. """

        indi_server = PanIndiServer()
        pid = indi_server._proc.pid
        fifo_file = indi_server._fifo

        assert pid > 0, "No PID found"
        assert os.getpgid(pid), "OS Can't find PID"
        assert indi_server.is_connected, "Server not connected"

        del indi_server
        assert os.getpgid(pid) is not True, "Server still running, didn't shut down properly"
        assert os.path.exists(fifo_file) is not True, "FIFO still exists"

    def test_device_create(self):
        """ Create a device, no server """

        device = None
        with pytest.raises(TypeError):
            device = PanIndiDevice()

        name = 'TestDevice'
        driver = 'indi_simulator_ccd'

        device = PanIndiDevice(name, driver)
        assert isinstance(device, PanIndiDevice), "Didn't return a device"

        assert device.is_loaded is not True, "Device driver not loaded"
        assert device.is_connected is not True, "Device not connected"

    def test_basic(self):
        """ Create a server and a device. Connect device """
        indi_server = PanIndiServer()

        assert indi_server.is_connected, "Server not connected"

        name = 'TestDevice'
        driver = 'indi_simulator_ccd'
        device = PanIndiDevice(name, driver)

        indi_server.load_driver(name, driver)

        assert device.is_loaded, "Device driver not loaded"
        del indi_server
<commit_msg>Adding test for basic webcam connectivity; cleaning up some of the INDI client tests<commit_after>import os
import pytest

from ..utils.indi import PanIndiServer, PanIndiDevice
from ..utils import has_logger


@has_logger
class TestIndiBasics(object):
    """ Class for testing INDI modules """

    def test_server_create_and_delete(self):
        """ Creates a server with no config, test it is there, delete it and make sure gone. """
        self.logger.info("Running test_server_create_and_delete")

        indi_server = PanIndiServer()
        pid = indi_server._proc.pid
        fifo_file = indi_server._fifo

        assert pid > 0, "No PID found"
        assert os.getpgid(pid), "OS Can't find PID"
        assert indi_server.is_connected, "Server not connected"

        del indi_server
        assert os.getpgid(pid) is not True, "Server still running, didn't shut down properly"
        assert os.path.exists(fifo_file) is not True, "FIFO still exists"

    def test_device_create(self):
        """ Create a device, no server """
        self.logger.info("Running test_device_create")

        device = None
        with pytest.raises(TypeError):
            device = PanIndiDevice()

        name = 'TestDevice'
        driver = 'indi_simulator_ccd'

        device = PanIndiDevice(name, driver)
        assert isinstance(device, PanIndiDevice), "Didn't return a device"

        assert device.is_loaded is not True, "Device driver not loaded"
        assert device.is_connected is not True, "Device not connected"

    def test_basic(self):
        """ Create a server and a device. Connect device """

        self.logger.info("Running test_basic")

        indi_server = PanIndiServer()

        assert indi_server.is_connected, "Server not connected"

        name = 'TestDevice'
        driver = 'indi_simulator_ccd'
        device = PanIndiDevice(name, driver)

        indi_server.load_driver(name, driver)

        assert device.is_loaded, "Device driver not loaded"
        del indi_server

    def test_v4l2(self):
        """ Create a server and a device. Connect webcam device and take a picture """

        self.logger.info("Running test_v4l2")

        indi_server = PanIndiServer()

        assert indi_server.is_connected, "Server not connected"

        name = 'TestWebCam'
        driver = 'indi_v4l2_ccd'
        device = PanIndiDevice(name, driver)

        indi_server.load_driver(name, driver)

        device.connect()

        assert device.is_connected, "WebCam is not on"

        assert device.is_loaded, "Device driver not loaded"

{'fraction_non_alphanumeric': 0.08315911730545877, 'fraction_numerical': 0.0018583042973286876, 'mean_word_length': 2.7378472222222223, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1536450', 'n_tokens_mistral': 1279, 'n_tokens_neox': 1221, 'n_words': 384}