Commit c3348e80 authored by Marco Buttu's avatar Marco Buttu
Browse files

telescope class attribute, clearOffset() -> setOffset(0)

In some tests we were using clearSystemOffset(axis_code) and
clearUserOffset(axis_code) instead of clearXXXOffset(servo_name).
For now the workaround is calling setXXXOffset(axis_code) instead
of clearXXXOffset(axis_code)
parent fa7699ba
Loading
Loading
Loading
Loading
+0 −87
Original line number Diff line number Diff line
import math
import time
import os
from datetime import datetime

import unittest2 # https://pypi.python.org/pypi/unittest2
import Management
import MinorServo
import Antenna
from Acspy.Common.TimeHelper import getTimeStamp
from Acspy.Clients.SimpleClient import PySimpleClient


__author__ = "Marco Buttu <mbuttu@oa-cagliari.inaf.it>"

class TestStartScan(unittest2.TestCase):
    """Test the MinorServoBoss.startScan() behavior"""

    def setUp(self):    
        code = 'KKG' if os.getenv('TARGETSYS') == 'SRT' else 'KKC'
        if hasattr(self, 'boss') and self.boss.isReady():
            pass
        else:
            client = PySimpleClient()
            self.boss = client.getComponent('MINORSERVO/Boss')
            self.boss.setup(code)
            t0 = datetime.now()
            while not self.boss.isReady() and (datetime.now() - t0).seconds < 60*5):
                time.sleep(2)
            self.assertTrue(self.boss.isReady()) # Timeout expired?

        self.assertEqual(self.boss.getActualSetup(), code)

        self.scan = MinorServo.MinorServoScan(
            range=50,
            total_time=500000000, # 50 seconds
            axis_code='SRP_TZ',
            is_empty_scan=False)

        self.antennaInfo = Antenna.TRunTimeParameters(
            targetName='dummy',
            azimuth=math.pi,
            elevation=math.pi/8,
            startEpoch=getTimeStamp().value + 100000000,
            onTheFly=False,
            slewingTime=100000000,
            section=Antenna.ANT_SOUTH,
            axis=Management.MNG_TRACK,
            timeToStop=0)

        self.boss.setElevationTracking('OFF')
        self.boss.setASConfiguration('OFF')

    def testStartASAP(self):
        """Check the behavior when the scan must start as soon as possible"""
        timeBeforeScan = getTimeStamp().value
        startTime = 0
        self.boss.startScan(startTime, self.scan, self.antennaInfo) 
        p_a = self.boss.getAxesPosition(startTime.value)['SRP_TZ']
        total_time = (self.scan.total_time + 10000000) / 10**7
        print 'starting the scan; time required: %s seconds' %total_time
        time.sleep(total_time) # Wait until the end end of the scan
        p_b = self.boss.getAxesPosition(startTime.value + self.scan.total_time)['SRP_TZ']
        self.assertGreater(startTime, timeBeforeScan)
        self.assertTrue(self.boss.isScanActive())
        self.assertFalse(self.boss.isScanning())
        self.assertAlmostEqual(abs(p_a - p_b), self.scan.range, places=2)

    def testStartAtGivenTime(self):
        """Check the behavior when the scan must start at a given time"""
        timeBeforeScan = getTimeStamp().value
        startTime = getTimeStamp().value + 60*10**7 # Start in a minute from now
        self.boss.startScan(startTime, self.scan, self.antennaInfo) 
        p_a = self.boss.getAxesPosition(startTime.value)['SRP_TZ']
        total_time = (self.scan.total_time + 10000000) / 10**7
        print 'starting the scan; time required: %s seconds' %total_time
        time.sleep(total_time) # Wait until the end end of the scan
        p_b = self.boss.getAxesPosition(startTime.value + self.scan.total_time)['SRP_TZ']
        self.assertGreater(startTime, timeBeforeScan)
        self.assertTrue(self.boss.isScanActive())
        self.assertFalse(self.boss.isScanning())
        self.assertAlmostEqual(abs(p_a - p_b), self.scan.range, places=2)


if __name__ == '__main__':
    unittest2.main()
+10 −4
Original line number Diff line number Diff line
@@ -19,16 +19,22 @@ __author__ = "Marco Buttu <mbuttu@oa-cagliari.inaf.it>"

class TestClearUserOffset(unittest2.TestCase):

    def setUp(self):
        client = PySimpleClient()
        self.boss = client.getComponent('MINORSERVO/Boss')
    telescope = os.getenv('TARGETSYS')

    @classmethod
    def setUpClass(cls):
        cls.client = PySimpleClient()
        cls.boss = cls.client.getComponent('MINORSERVO/Boss')
        
    @classmethod
    def tearDownClass(cls):
        cls.client.releaseComponent('MINORSERVO/Boss')

    def test_wrong_servo_name(self):
        """Raise a MinorServoErrorsEx in case of wrong servo name"""
        with self.assertRaises(MinorServoErrorsEx):
            self.boss.clearUserOffset('FOO')


if __name__ == '__main__':
    if 'Configuration' in os.getenv('ACS_CDB'):
        unittest2.main() # Real test using the antenna CDB
+2 −1
Original line number Diff line number Diff line
@@ -20,8 +20,9 @@ __author__ = "Marco Buttu <mbuttu@oa-cagliari.inaf.it>"

class TestGetAxesInfo(unittest2.TestCase):

    telescope = os.getenv('TARGETSYS')

    def setUp(self):
        self.telescope = os.getenv('TARGETSYS')
        self.client = PySimpleClient()
        self.boss = self.client.getComponent('MINORSERVO/Boss')
        self.setup_code = "CCB" if self.telescope == "SRT" else "CCC"
+7 −2
Original line number Diff line number Diff line
@@ -12,9 +12,14 @@ __author__ = "Marco Buttu <mbuttu@oa-cagliari.inaf.it>"

class TestGetCentralScanPosition(unittest2.TestCase):

    telescope = os.getenv('TARGETSYS')

    def setUp(self):
        client = PySimpleClient()
        self.boss = client.getComponent('MINORSERVO/Boss')
        self.client = PySimpleClient()
        self.boss = self.client.getComponent('MINORSERVO/Boss')

    def tearDown(self):
        self.client.releaseComponent('MINORSERVO/Boss')

    def test_scan_not_active(self):
        """Raise a MinorServoErrorsEx if the scan is not active"""
+9 −7
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@ __author__ = "Marco Buttu <mbuttu@oa-cagliari.inaf.it>"

class PositionTest(unittest2.TestCase):

    telescope = os.getenv('TARGETSYS')

    @classmethod
    def setUpClass(cls):
        cls.client = PySimpleClient()
@@ -29,7 +31,6 @@ class PositionTest(unittest2.TestCase):
        cls.client.releaseComponent('MINORSERVO/Boss')

    def setUp(self):
        self.telescope = os.getenv('TARGETSYS')
        self.axis_code='SRP_TZ' if self.telescope == 'SRT' else 'Z'
        setupCode = 'KKG' if self.telescope == 'SRT' else 'CCC'
        # Wait (maximum one minute) in case the boss is parking
@@ -54,21 +55,22 @@ class PositionTest(unittest2.TestCase):
        self.idx = axes.index(self.axis_code)

    def tearDown(self):
        self.boss.clearUserOffset(self.axis_code)
        # self.boss.clearUserOffset(self.axis_code)
        self.boss.setUserOffset(self.axis_code, 0)
        self.wait_tracking()

    def test_get_current_position(self):
        timestamp = getTimeStamp().value
        position = self.get_position()
        position_now = self.get_position(timestamp)
        self.assertAlmostEqual(position, position_now, 0.1)
        self.assertAlmostEqual(position, position_now, delta=0.1)

    def test_get_offset_position(self):
        position = self.get_position()
        self.boss.setUserOffset(self.axis_code, 10)
        self.wait_tracking()
        position_now = self.get_position()
        self.assertAlmostEqual(position_now, position + 10, 0.1)
        self.assertAlmostEqual(position_now, position + 10, delta=0.1)

    def test_get_past_position(self):
        timestamp = getTimeStamp().value
@@ -76,16 +78,16 @@ class PositionTest(unittest2.TestCase):
        self.boss.setUserOffset(self.axis_code, 10)
        self.wait_tracking()
        position_past = self.get_position(timestamp)
        self.assertAlmostEqual(position, position_past, 0.1)
        self.assertAlmostEqual(position, position_past, delta=0.1)

    def test_get_past_position_with_sleep(self):
        timestamp = getTimeStamp().value
        position = self.get_position()
        self.boss.setUserOffset(self.axis_code, 10)
        self.boss.setUserOffset(self.axis_code, delta=10)
        self.wait_tracking()
        time.sleep(10)
        position_past = self.get_position(timestamp)
        self.assertAlmostEqual(position, position_past, 0.1)
        self.assertAlmostEqual(position, position_past, delta=0.1)

    def wait_tracking(self):
        while not self.boss.isTracking():
Loading