コード例 #1
0
ファイル: test_datasinks.py プロジェクト: umithardal/nicos
 def test_bersans_sink(self, session):
     bersansfile = path.join(session.experiment.datapath, 'D0000168.001')
     assert path.isfile(bersansfile)
     contents = readFile(bersansfile)
     assert '%File' in contents
     assert 'User=testuser' in contents  # BerSANS headers
     assert 'Exp_proposal=p1234' in contents  # NICOS headers
     assert ('0,' * 127 + '0') in contents  # data
コード例 #2
0
ファイル: test_datasinks.py プロジェクト: umithardal/nicos
 def test_filecounters(self, session):
     # check contents of counter files
     exp = session.experiment
     for directory, ctrs in zip(
         [exp.dataroot, exp.proposalpath, exp.samplepath],
         [('scan 43', 'point 172'), ('scan 1', 'point 5'),
          ('scan 1', 'point 5')]):
         counterfile = path.join(directory, exp.counterfile)
         assert path.isfile(counterfile)
         contents = readFile(counterfile)
         assert set(contents) == set(ctrs)
コード例 #3
0
 def __init__(self):
     try:
         if not session.experiment or not session.experiment.propdb:
             credpath = path.join(path.expanduser('~'), '.nicos',
                                  'credentials')
             credentials = readFile(credpath)
         else:
             credentials = readFile(session.experiment.propdb)
     except IOError as e:
         raise ConfigurationError('Can\'t read credentials '
                                  'for propdb-access from file: %s' % e)
     credentials = credentials[0]
     try:
         self.user, hostdb = credentials.split('@')
         self.host, self.db = hostdb.split(':')
     except ValueError:
         raise ConfigurationError('%r is an invalid credentials string '
                                  '("user@host:dbname")' % credentials)
     if DB is None:
         raise ConfigurationError('MySQL adapter is not installed')
コード例 #4
0
    def sicscounter(self):
        try:
            lines = readFile(self.sicscounterfile)
        except IOError:
            self.updateSicsCounterFile(0)
            return 0
        if lines:
            return int(lines[0].strip())

        # the counter is not yet in the file
        return 0
コード例 #5
0
ファイル: test_datasinks.py プロジェクト: umithardal/nicos
    def test_raw_sinks(self, session):
        # check contents of files written by the raw sink
        rawfile = path.join(session.experiment.datapath, 'p1234_1.raw')
        assert path.isfile(rawfile)
        assert path.getsize(rawfile) == 128 * 128 * 4  # 128x128 px, 32bit ints

        headerfile = path.join(session.experiment.datapath, 'p1234_1.header')
        assert path.isfile(headerfile)
        contents = readFile(headerfile)
        assert contents[0] == '### NICOS Device snapshot V2.0'
        assert '### Sample and alignment' in contents
        assert any(line.strip() == 'Exp_proposal : p1234' for line in contents)

        logfile = path.join(session.experiment.datapath, 'p1234_1.log')
        assert path.isfile(logfile)
        contents = readFile(logfile)
        assert contents[0].startswith('# dev')
        assert len(contents) >= 3  # at least: header, motor2, tdev
        for line in contents[1:]:
            name, mean, stdev, minv, maxv = line.split()
            if name == 'motor2':
                assert mean == minv == maxv == '0.000'
                assert stdev == 'inf'

        if hasattr(os, 'link'):
            linkfile = path.join(session.experiment.datapath, '00000168.raw')
            assert path.isfile(linkfile)  # hardlink
            assert os.stat(linkfile).st_ino == os.stat(rawfile).st_ino

        # check files written by the single-raw sink
        rawfile = path.join(session.experiment.datapath, 'single',
                            '43_172.raw')
        assert path.isfile(rawfile)
        assert path.getsize(rawfile) > 128 * 128 * 4  # data plus header

        if hasattr(os, 'link'):
            # this entry in filenametemplate is absolute, which means relative to
            # the dataroot, not the current experiment's datapath
            linkfile = path.join(session.experiment.dataroot, '00000172.raw')
            assert path.isfile(linkfile)  # hardlink
            assert os.stat(linkfile).st_ino == os.stat(rawfile).st_ino
コード例 #6
0
ファイル: test_datasinks.py プロジェクト: umithardal/nicos
    def test_scan_sink(self, session):
        # check contents of ASCII scan data file
        scanfile = path.join(session.experiment.datapath, 'p1234_00000043.dat')
        assert path.isfile(scanfile)
        contents = readFile(scanfile)
        assert contents[0].startswith('### NICOS data file')
        assert '### Scan data' in contents
        assert contents[-1].startswith('### End of NICOS data file')

        # check counter attributes
        scan = session.experiment.data.getLastScans()[-1]
        assert scan.counter == 43
        assert scan.propcounter == 1
        assert scan.samplecounter == 1
        assert session.experiment.lastscan == 43
        assert session.experiment.lastpoint == 172
コード例 #7
0
def test_sinqascii(session):
    # check contents of ASCII scan data file
    scanfile = path.join(session.experiment.datapath,
                         'test%sn000043.dat' % year)
    assert path.isfile(scanfile)
    contents = readFile(scanfile)
    assert (contents[0] == '**** SINQASCII TEST TEMPLATE ****')
    assert (contents[1].find(scanfile) > 0)
    assert (contents[3] == 'motor2 = 0.000')
    assert (contents[4] == 'motor2 softzero = 0.000')
    assert (contents[5] == 'Title = TomatenOxid')
    assert (contents[6] == 'ScriptTest = Oops')
    assert (contents[-10] == 'motor2 zero = 0.000')
    assert (contents[-9] == 'Scanning Variables: motor2, Steps: 1.0')
    assert (contents[-8] == '5 Points, Mode: Timer,Preset 0.005000')
    assert (contents[-7] == 'NP  motor2   COUNTS     MONITOR1   TIME')
    # cannot test data content because they consist or random runmbers
    assert (contents[-1] == 'END-OF-DATA')
コード例 #8
0
ファイル: caress.py プロジェクト: umithardal/nicos
 def doReadRunnumber(self):
     return int(readFile(self._counterpath)[0])