Best Python code snippet using avocado_python
MRT_PY4_influxDB.py
Source:MRT_PY4_influxDB.py  
1# verified 12 July 2018: working2import numpy as np3#import healpy as hp4import astropy as ap5import time6import mrtstate7import MRT_FUNC_PY4_influxDB as mrtf8#%9# ----------------------------------------------------------------------------10# Begin11# ----------------------------------------------------------------------------12# Notify the user13print ('Opening serial port',mrtf.port)14print ('with baud',mrtf.baud)15""" For reasons unclear, the Mac appears to assert DTR on serial connection,16whereas the Pi does not.  So we will be super explicit. """17# Open the port18ser = mrtf.serial.Serial(mrtf.port, mrtf.baud)19print ('Before flushing buffers')20print ('Bytes in waiting', ser.inWaiting())21mrtf.FlushSerialBuffers(ser)22print ('After flushing buffers')23print ('Bytes in waiting', ser.inWaiting())24print ('Resetting Arduino')25print ('Before reset')26print ('Bytes in waiting', ser.inWaiting())27mrtf.ResetArduinoUno(ser,timeout=15,nbytesExpected=mrtf.nIDBytes)28# I don't understand why ARDUINO MRT is 18 bytes ...29print ('After reset')30print ('Bytes in waiting', ser.inWaiting())31print (ser.inWaiting())32output = mrtf.read_ser_buffer_to_eot(ser)33print(output)34#%%35# For the nominal mounting in the observatory36#eloff = 35.537#azoff = -191.38# For a general setup facing south39#eloff = 35.540#azoff = -180.41# Just start at zero42mrtstate.offsets['eloff'] = 0.43mrtstate.offsets['azoff'] = -180.44print(mrtstate.offsets)45# Initialize the current state46ser.write(mrtf.REPORT_STATE)47mrtstate.state = mrtf.readState(ser)48mrtf.PrintState()49#%%50""" Basic mode of operation should be that the Python side handles the user 51interface and menu, and sends groups of atomic commands.  The Arduino always52reports its state in response to any command, including whether the last 53command was valid.  Because I don't think we want to command individual steps,54but rather scans, that command is special """55operate=True56while(operate):57    var = input("Enter command to transmit, H for help, Q to quit: ")58    if not var == 'Q':59        if (var == 'M'): # Make a map!60            cs = mrtf.StdCmd(ser,mrtf.REPORT_STATE)61            #az,el,pwr,mp,azi,eli = mrtf.RasterMap()62            # Update the current state63            current_state = mrtstate.state64            #mrtf.PrintState()65            mrtf.RasterMap()66            current_state =  mrtf.StdCmd(ser,mrtf.REPORT_STATE)67            mrtf.PrintState()68        elif (var == 'MS'): # Make a map of the South Sky69            cs = mrtf.StdCmd(ser,mrtf.REPORT_STATE)70            #az,el,pwr,mp,azi,eli = mrtf.ScanSouthSky(cs)71            # Update the current state72            current_state = mrtstate.state73            mrtf.ScanSouthSky()74            current_state =  mrtf.StdCmd(ser,mrtf.REPORT_STATE)75            mrtf.PrintState()76        elif (var == 'G'):77            cs = mrtf.StdCmd(ser,mrtf.REPORT_STATE)78            current_state = mrtstate.state79            mrtf.GoTo()80            current_state =  mrtf.StdCmd(ser,mrtf.REPORT_STATE)81            mrtf.PrintState()82        elif (var == 'H'):83            mrtf.PrintMenu()84        elif (var == 'CS'):85            #print(mrtstate.state)86            mrtf.PrintState()87        elif (var == 'GA'):88            cs = mrtf.StdCmd(ser,mrtf.REPORT_STATE)89            current_state = mrtstate.state90            mrtf.GoAz()91            current_state =  mrtf.StdCmd(ser,mrtf.REPORT_STATE)92            mrtf.PrintState()93        elif (var == 'GE'):94            cs = mrtf.StdCmd(ser,mrtf.REPORT_STATE)95            current_state = mrtstate.state96            mrtf.GoEl()97            current_state =  mrtf.StdCmd(ser,mrtf.REPORT_STATE)98            mrtf.PrintState()99        elif (var == 'S'):100            print ("Sending "+var)101            ser.write(mrtf.SCAN)102            deg = input("Enter number of degrees to turn: ")103            print ("Sending "+deg)104            ser.write(str.encode(deg))105            print ("Reading data")106            ndata = mrtf.readStream(ser)107            current_state = mrtf.readState(ser)108            mrtf.PrintState()109            # Convert110            #ndata = numpyState(ndata)111            # Save112            print(mrtstate.directory)113            print(mrtstate.directory+time.ctime().replace(' ','_')+'.npz')114            np.savez(file=mrtstate.directory+time.ctime().replace(' ','_')+'.npz',ndata=ndata)115            # Plot116            mrtf.PlotData(ndata)117        elif (var == 'A'):118            print ("Sending "+var)119            ser.write(mrtf.AZIMUTH)120            current_state =  mrtf.StdCmd(ser,mrtf.REPORT_STATE)121            mrtf.PrintState()122        elif (var == 'L'):123            print ("Sending "+var)124            ser.write(mrtf.ELEVATION)125            current_state =  mrtf.StdCmd(ser,mrtf.REPORT_STATE)126            mrtf.PrintState()127        elif (var == 'E'):128            print ("Sending "+var)129            ser.write(mrtf.ENABLE)130            current_state =  mrtf.StdCmd(ser,mrtf.REPORT_STATE)131            mrtf.PrintState()132        elif (var == 'D'):133            print ("Sending "+var)134            ser.write(mrtf.DISABLE)135            current_state =  mrtf.StdCmd(ser,mrtf.REPORT_STATE)136            mrtf.PrintState()137        elif (var == 'ETGOHOME'):138            print ("Sending "+var)139            mrtf.ETGOHOME()140            mrtf.PrintState()141            newel = float(0.0)142            curr_eloff = mrtstate.offsets['eloff']143            arduino_el = mrtstate.state['elDeg'] + curr_eloff144            mrtstate.offsets['eloff'] = arduino_el - newel145            current_state =  mrtf.StdCmd(ser,mrtf.REPORT_STATE)146            mrtf.PrintState()147        elif (var == 'X'):148            Ndatapts = input("Enter number of data points: ")149            ser.write(mrtf.REPORT_STATE)150            # Initialize the data variable151            data = mrtf.readState(ser)152            for i in np.arange(int(Ndatapts)-1):153                ser.write(mrtf.REPORT_STATE)154                current_state = mrtf.readState(ser)155                mrtf.PrintState()156                # Trick it by sending invalid commands and reading them back157                #ser.write(REPORT_STATE)158                #read_ser_buffer_to_eot(ser)159                #dummy = readState(ser)160                #for key in data.keys():161                #    data[key].append(dummy[key][0])162            #ndata = numpyState(data)163            #PlotData(ndata)164        elif (var == 'CCW'):165            mrtf.StdCmd(ser, mrtf.AZIMUTH)166            mrtf.StdCmd(ser, mrtf.ENABLE)167            mrtf.StdCmd(ser, mrtf.FORWARD)168            mrtf.PrintState()169        elif (var == 'CW'):170            mrtf.StdCmd(ser, mrtf.AZIMUTH)171            mrtf.StdCmd(ser, mrtf.ENABLE)172            mrtf.StdCmd(ser, mrtf.REVERSE)173            mrtf.PrintState()174        elif (var == 'UP'):175            mrtf.StdCmd(ser, mrtf.ELEVATION)176            mrtf.StdCmd(ser, mrtf.ENABLE)177            mrtf.StdCmd(ser, mrtf.FORWARD)178            mrtf.PrintState()179        elif (var == 'DOWN'):180            mrtf.StdCmd(ser, mrtf.ELEVATION)181            mrtf.StdCmd(ser, mrtf.ENABLE)182            mrtf.StdCmd(ser, mrtf.REVERSE)183            mrtf.PrintState()184        elif (var == 'SETPOS'):185            mrtf.PrintState()186            newaz = float(input("New azimuth: "))187            #print('Current azimuth', mrtstate.state['azDeg'])188            curr_azoff = mrtstate.offsets['azoff']189            #print('Current offset', curr_azoff)190            arduino_az = mrtstate.state['azDeg'] + curr_azoff191            mrtstate.offsets['azoff'] = arduino_az - newaz 192            #print(mrtf.azoff)193            newel = float(input("New elevation: "))194            curr_eloff = mrtstate.offsets['eloff']195            arduino_el = mrtstate.state['elDeg'] + curr_eloff196            mrtstate.offsets['eloff'] = arduino_el - newel197            current_state =  mrtf.StdCmd(ser,mrtf.REPORT_STATE)198            mrtf.PrintState()199        elif (var == 'X'):200            Ndatapts = input("Enter number of data points: ")201            ser.write(mrtf.REPORT_STATE)202            # Initialize the data variable203            data = mrtf.readState(ser)204            for i in np.arange(int(Ndatapts)-1):205                ser.write(mrtf.REPORT_STATE)206                current_state = mrtf.readState(ser)207                mrtf.PrintState()208        else:209            # Commands that get passed along210            print("Sending command direct to Arduino")211            print ("Sending "+var)212            ser.write(str.encode(var))213            # Read back any reply214            #read_ser_buffer_to_eot(ser)215            current_state = mrtf.readState(ser)216            mrtf.PrintState()217    else:218        operate = False...test_report_state.py
Source:test_report_state.py  
...5from homeassistant.setup import async_setup_component6from homeassistant.util.dt import utcnow7from . import BASIC_CONFIG8from tests.common import async_fire_time_changed9async def test_report_state(hass, caplog, legacy_patchable_time):10    """Test report state works."""11    assert await async_setup_component(hass, "switch", {})12    hass.states.async_set("light.ceiling", "off")13    hass.states.async_set("switch.ac", "on")14    with patch.object(15        BASIC_CONFIG, "async_report_state_all", AsyncMock()16    ) as mock_report, patch.object(report_state, "INITIAL_REPORT_DELAY", 0):17        unsub = report_state.async_enable_report_state(hass, BASIC_CONFIG)18        async_fire_time_changed(hass, utcnow())19        await hass.async_block_till_done()20    # Test that enabling report state does a report on all entities21    assert len(mock_report.mock_calls) == 122    assert mock_report.mock_calls[0][1][0] == {23        "devices": {24            "states": {25                "light.ceiling": {"on": False, "online": True},26                "switch.ac": {"on": True, "online": True},27            }28        }29    }30    with patch.object(31        BASIC_CONFIG, "async_report_state_all", AsyncMock()...test_report_states.py
Source:test_report_states.py  
1import unittest2from spynnaker.pyNN.utilities.conf import config3from spinn_front_end_common.utilities.utility_objs.report_states import ReportState4class TestReportStates(unittest.TestCase):5    def test_partitioner_report(self):6        report_state = ReportState()7        self.assertEqual(report_state.partitioner_report,config.getboolean(8            "Reports", "writePartitionerReports"))9    def test_placer_report(self):10        report_state = ReportState()11        self.assertEqual(report_state.placer_report,config.getboolean(12            "Reports", "writePlacerReports"))13    def test_router_report(self):14        report_state = ReportState()15        self.assertEqual(report_state.router_report,config.getboolean(16            "Reports", "writeRouterReports"))17    def test_router_dat_based_report(self):18        report_state = ReportState()19        self.assertEqual(report_state.router_dat_based_report,config.getboolean(20            "Reports", "writeRouterDatReport"))21    def test_routing_info_report(self):22        report_state = ReportState()23        self.assertEqual(report_state.routing_info_report,config.getboolean(24            "Reports", "writeRouterInfoReport"))25    def test_data_spec_report(self):26        report_state = ReportState()27        self.assertEqual(report_state.data_spec_report,config.getboolean(28            "Reports", "writeTextSpecs"))29    def test_write_reload_steps(self):30        report_state = ReportState()31        self.assertEqual(report_state.write_reload_steps,config.getboolean(32            "Reports", "writeReloadSteps"))33    def test_generate_pacman_report_states(self):34        report_state = ReportState()35        pacman_report_state = \36            report_state.generate_pacman_report_states()37        self.assertEqual(report_state.partitioner_report,38                         pacman_report_state.partitioner_report)39        self.assertEqual(report_state.placer_report,40                         pacman_report_state.placer_report)41        self.assertEqual(report_state.router_report,42                         pacman_report_state.router_report)43        self.assertEqual(report_state.router_dat_based_report,44                         pacman_report_state.router_dat_based_report)45        self.assertEqual(report_state.routing_info_report,46                         pacman_report_state.routing_info_report)47    def test_generate_time_recordings_for_performance_measurements(self):48        report_state = ReportState()49        self.assertEqual(50            report_state.generate_time_recordings_for_performance_measurements,51            config.getboolean("Reports", "outputTimesForSections"))52if __name__ == '__main__':...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
