示例#1
0
文件: testutil.py 项目: slnc/cs425cp
 def tearDown(self):
     # Make sure all initialized chat sessions are closed
     for c in self._chat_sessions:
         try:
             timeout(c.stop, timeout_duration=1)
             # slnc: Without this tests hang, I still don't know the reason. 
         except:
             pass
示例#2
0
 def test_fibonnacci(self):
     for n, expected in [
         (0, 0),
         (1, 1),
         (100, 354224848179261915075),
     ]:
         with timeout():
             self.assertEqual(expected, optimized_fibonacci(n))
示例#3
0
    def __init__(self):
        dht = Dht(dht_read_params=config.dht_read_params)
        self.bathroom_temperature = UberAdapter(
            dht, 1, gauge_caption='mieszkanie.lazienka.temp')
        self.bathroom_humidity = UberAdapter(
            dht, 0, gauge_caption='mieszkanie.lazienka.humidity')
        self.bathroom_humidity_slope = self.Sloper(
            self.bathroom_humidity)  # !!! TODO fixme!!!

        ot = OnlineWeather()
        self.online_temperature = UberAdapter(
            ot, 1, gauge_caption='mieszkanie.temp_zew')
        self.online_humidity = UberAdapter(ot,
                                           0,
                                           gauge_caption='mieszkanie.humi_zew')

        self.saloon_temperature = Ds18(sensor_id='28-0115915119ff',
                                       gauge_caption='mieszkanie.temp1')
        self.core_temperature = CoreTemp(gauge_caption='malina0.core_temp')

        try:
            with timeout(5):
                # import rpyc
                # registrar = rpyc.utils.registry.TCPRegistryClient('5.8.0.8')
                # ret = rpyc.utils.factory.discover('SmartieSlave', registrar=registrar)
                # conn = rpyc.connect(*ret[0])

                from disco import DiscoProxy2
                dp2 = DiscoProxy2()

                conn = dp2.SmartieSlave

                self.radiator_temperature = RemoteAdapter(
                    Ds18,
                    gauge_caption='mieszkanie.kaloryfer.temp',
                    sensor_id='28-0115916115ff',
                    conn=conn)

                remote_dht = RemoteAdapter(
                    Dht,
                    dht_read_params='Adafruit_DHT.DHT22, 4',
                    conn=conn,
                    timing_caption='malina2.measurments_time.dht22read')

                self.bedroom_temperature = UberAdapter(
                    remote_dht, 1, gauge_caption='mieszkanie.test22.temp')
                self.bedroom_humidity = UberAdapter(
                    remote_dht, 0, gauge_caption='mieszkanie.test22.humidity')

                self.malina2_core_temperature = RemoteAdapter(
                    CoreTemp,
                    gauge_caption='malina2.core_temp',
                    timing_caption='malina2.measurments_time.coretemp',
                    conn=conn)

        except Exception as e:
            log.exception(e)
示例#4
0
def getdata():
    def _getdata_raw():
        # response = requests.get('http://api.apixu.com/v1/current.json?key=%s&q=Wroclaw'%('keystring'))
        # in my network 5.8.0.0/16 is not routed outside
        # this is a caching proxy running very similar code but it has api key embedded
        # log.info('Doing apixu request...')
        response = requests.get(config.apixu_link)
        # log.info('apixu req done')
        return response.json()

    # <editor-fold desc="example output">
    example_output = {
        'location': {
            'name': 'Wroclaw',
            'region': '',
            'country': 'Poland',
            'lat': 51.1,
            'lon': 17.03,
            'tz_id': 'Europe/Warsaw',
            'localtime_epoch': 1497957239,
            'localtime': '2017-06-20 13:13'
        },
        'current': {
            'last_updated_epoch': 1497956418,
            'last_updated': '2017-06-20 13:00',
            'temp_c': 31.0,
            'is_day': 1,
            'condition': {
                'text': 'Sunny',
                'icon': '//cdn.apixu.com/weather/64x64/day/113.png',
                'code': 1000
            },
            'wind_kph': 20.2,
            'wind_degree': 270,
            'wind_dir': 'W',
            'pressure_mb': 1014.0,
            'pressure_in': 30.4,
            'precip_mm': 0.0,
            'humidity': 33,
            'cloud': 0,
            'feelslike_c': 30.4,
            'vis_km': 10.0,
            'vis_miles': 6.0
        }
    }
    # </editor-fold>

    with shelve.open('/tmp/apixu_last_weather') as db:
        olddata = db.get('olddata', dict())
        need_update = False
        if 'current' in olddata:
            last_ts = olddata['current']['last_updated_epoch']

            if time() - last_ts >= 7 * 60:
                need_update = True
        else:
            need_update = True

        if need_update:
            try:
                with timeout(5):
                    olddata = _getdata_raw()
                    db['olddata'] = olddata
            except Exception as e:
                log.debug(e)

        return olddata
# T E S T   S C R I P T
# The approach is to open a large file in Dart Editor and make changes to it.
# If the changes appear on-screen in a reasonable amount of time then
# the test passes. If anything else happens the test fails.

init_logger()
#util.start_dart_editor()
init_dart_editor()
util.activate_editor()
util.goto_line(1)
for i in range(6): # Not the same as goto_line(6)
  type(Key.DOWN)
type(Key.ENTER)
#analysis_time("ENTER")
result = util.timeout(analysis_time,args=["ENTER"],kwargs={},timeout_duration=10.0,default="fail")
if result == "fail":
  logger.info("Analysis took too long after initial ENTER")
  logger.info("FAIL")
  exit(0)
edit_begin = time.clock()
add_some_code()
edit_done = exists(SIGNAL, max_edit_time)
edit_end = time.clock()
if edit_done:
  logger.info(" Editing took " + str(edit_end - edit_begin) + " seconds")
  wait(0.5)
  analysis_time("adding some code")
  util.menu_bar_select("File", "Revert")
  analysis_time("revert the changes")
  util.quit_app()
示例#6
0
# The approach is to open a large file in Dart Editor and make changes to it.
# If the changes appear on-screen in a reasonable amount of time then
# the test passes. If anything else happens the test fails.

init_logger()
#util.start_dart_editor()
init_dart_editor()
util.activate_editor()
util.goto_line(1)
for i in range(6):  # Not the same as goto_line(6)
    type(Key.DOWN)
type(Key.ENTER)
#analysis_time("ENTER")
result = util.timeout(analysis_time,
                      args=["ENTER"],
                      kwargs={},
                      timeout_duration=10.0,
                      default="fail")
if result == "fail":
    logger.info("Analysis took too long after initial ENTER")
    logger.info("FAIL")
    exit(0)
edit_begin = time.clock()
add_some_code()
edit_done = exists(SIGNAL, max_edit_time)
edit_end = time.clock()
if edit_done:
    logger.info(" Editing took " + str(edit_end - edit_begin) + " seconds")
    wait(0.5)
    analysis_time("adding some code")
    util.menu_bar_select("File", "Revert")