text: # Copyright 2016-2020 Swiss National Supercomputing Centre (CSCS/ETH Zurich)
  # ReFrame Project Developers. See the top-level LICENSE file for details.
  #
  # SPDX-License-Identifier: BSD-3-Clause
  
  import reframe as rfm
  import reframe.utility.sanity as sn
  
  
  @rfm.simple_test
  class PrepostRunTest(rfm.RunOnlyRegressionTest):
      def __init__(self):
          self.descr = 'Pre- and post-run demo test'
          self.valid_systems = ['*']
          self.valid_prog_environs = ['*']
          self.prerun_cmds = ['source limits.sh']
          self.postrun_cmds = ['echo FINISHED']
          self.executable = './random_numbers.sh'
          numbers = sn.extractall(
              r'Random: (?P<number>\S+)', self.stdout, 'number', float
          )
          self.sanity_patterns = sn.all([
              sn.assert_eq(sn.count(numbers), 100),
              sn.all(sn.map(lambda x: sn.assert_bounded(x, 90, 100), numbers)),
              sn.assert_found(r'FINISHED', self.stdout)
          ])
  