Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions unittests/test_argparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#
# SPDX-License-Identifier: BSD-3-Clause

import pytest
import unittest

from reframe.frontend.argparse import ArgumentParser
Expand All @@ -27,36 +28,37 @@ def setUp(self):
self.foo_options.add_argument('--barfoo', action='store_true')

def test_arguments(self):
self.assertRaises(ValueError, self.foo_options.add_argument,
action='store', default='FOO')
with pytest.raises(ValueError):
self.foo_options.add_argument(action='store', default='FOO')

self.foo_options.add_argument('--foo-bar', action='store_true')
self.foo_options.add_argument('--alist', action='append', default=[])
options = self.parser.parse_args(['--foobar', '--foo-bar'])
self.assertTrue(options.foobar)
self.assertTrue(options.foo_bar)
assert options.foobar
assert options.foo_bar

def test_parsing(self):
options = self.parser.parse_args(
'--foo name --foolist gag --barfoo --unfoo'.split()
)
self.assertEqual('name', options.foo)
self.assertEqual(['gag'], options.foolist)
self.assertTrue(options.barfoo)
self.assertFalse(options.unfoo)
assert 'name' == options.foo
assert ['gag'] == options.foolist
assert options.barfoo
assert not options.unfoo

# Check the defaults now
self.assertFalse(options.foobar)
self.assertEqual('BAR', options.bar)
self.assertEqual([], options.barlist)
assert not options.foobar
assert 'BAR' == options.bar
assert [] == options.barlist

# Reparse based on the already loaded options
options = self.parser.parse_args(
'--bar beer --foolist any'.split(), options
)
self.assertEqual('name', options.foo)
self.assertEqual(['any'], options.foolist)
self.assertFalse(options.foobar)
self.assertFalse(options.unfoo)
self.assertEqual('beer', options.bar)
self.assertEqual([], options.barlist)
self.assertTrue(options.barfoo)
assert 'name' == options.foo
assert ['any'] == options.foolist
assert not options.foobar
assert not options.unfoo
assert 'beer' == options.bar
assert [] == options.barlist
assert options.barfoo
38 changes: 16 additions & 22 deletions unittests/test_buildsystems.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ def test_emit_from_env(self):
'CFLAGS="-Wall -std=c99" CXXFLAGS="-Wall -std=c++11" '
'FCFLAGS="-Wall" LDFLAGS="-dynamic" FOO=1'
]
self.assertEqual(expected,
self.build_system.emit_build_commands(self.environ))
assert expected == self.build_system.emit_build_commands(self.environ)

def test_emit_from_buildsystem(self):
super().setup_base_buildsystem()
Expand All @@ -70,13 +69,12 @@ def test_emit_from_buildsystem(self):
'CXXFLAGS="-Wall -std=c++11 -O3" FCFLAGS="-Wall -O3" '
'LDFLAGS="-static" FOO=1'
]
self.assertEqual(expected,
self.build_system.emit_build_commands(self.environ))
assert expected == self.build_system.emit_build_commands(self.environ)

def test_emit_no_env_defaults(self):
self.build_system.flags_from_environ = False
self.assertEqual(['make -j 1'],
self.build_system.emit_build_commands(self.environ))
assert (['make -j 1'] ==
self.build_system.emit_build_commands(self.environ))


class TestCMake(_BuildSystemTest, unittest.TestCase):
Expand All @@ -103,8 +101,7 @@ def test_emit_from_env(self):
'make -j 32 install'

]
self.assertEqual(expected,
self.build_system.emit_build_commands(self.environ))
assert expected == self.build_system.emit_build_commands(self.environ)

def test_emit_from_buildsystem(self):
super().setup_base_buildsystem()
Expand All @@ -124,13 +121,12 @@ def test_emit_from_buildsystem(self):

]
print(self.build_system.emit_build_commands(self.environ))
self.assertEqual(expected,
self.build_system.emit_build_commands(self.environ))
assert expected == self.build_system.emit_build_commands(self.environ)

def test_emit_no_env_defaults(self):
self.build_system.flags_from_environ = False
self.assertEqual(['cmake .', 'make -j 1'],
self.build_system.emit_build_commands(self.environ))
assert (['cmake .', 'make -j 1'] ==
self.build_system.emit_build_commands(self.environ))


class TestAutotools(_BuildSystemTest, unittest.TestCase):
Expand All @@ -154,8 +150,7 @@ def test_emit_from_env(self):
'make -j 32 check'

]
self.assertEqual(expected,
self.build_system.emit_build_commands(self.environ))
assert expected == self.build_system.emit_build_commands(self.environ)

def test_emit_from_buildsystem(self):
super().setup_base_buildsystem()
Expand All @@ -173,13 +168,12 @@ def test_emit_from_buildsystem(self):

]
print(self.build_system.emit_build_commands(self.environ))
self.assertEqual(expected,
self.build_system.emit_build_commands(self.environ))
assert expected == self.build_system.emit_build_commands(self.environ)

def test_emit_no_env_defaults(self):
self.build_system.flags_from_environ = False
self.assertEqual(['./configure', 'make -j 1'],
self.build_system.emit_build_commands(self.environ))
assert (['./configure', 'make -j 1'] ==
self.build_system.emit_build_commands(self.environ))


class TestSingleSource(_BuildSystemTest, unittest.TestCase):
Expand Down Expand Up @@ -224,8 +218,8 @@ def test_emit_from_env(self):
'-o foo.e %s' % (comp, flags,
self.build_system.srcfile, ldflags)
]
self.assertEqual(expected,
self.build_system.emit_build_commands(self.environ))
assert (expected ==
self.build_system.emit_build_commands(self.environ))

def test_emit_no_env(self):
super().setup_base_buildsystem()
Expand Down Expand Up @@ -256,5 +250,5 @@ def test_emit_no_env(self):
'-o foo.e %s' % (comp, flags,
self.build_system.srcfile, ldflags)
]
self.assertEqual(expected,
self.build_system.emit_build_commands(self.environ))
assert (expected ==
self.build_system.emit_build_commands(self.environ))
66 changes: 28 additions & 38 deletions unittests/test_check_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#
# SPDX-License-Identifier: BSD-3-Clause

import pytest
import unittest

import reframe.core.runtime as rt
Expand Down Expand Up @@ -47,67 +48,56 @@ def count_checks(self, filter_fn):
return sn.count(filter(filter_fn, self.checks))

def test_have_name(self):
self.assertEqual(1, self.count_checks(filters.have_name('check1')))
self.assertEqual(3, self.count_checks(filters.have_name('check')))
self.assertEqual(2, self.count_checks(filters.have_name(r'\S*1|\S*3')))
self.assertEqual(0, self.count_checks(filters.have_name('Check')))
self.assertEqual(3, self.count_checks(filters.have_name('(?i)Check')))
self.assertEqual(
2, self.count_checks(filters.have_name('(?i)check1|CHECK2'))
)
assert 1 == self.count_checks(filters.have_name('check1'))
assert 3 == self.count_checks(filters.have_name('check'))
assert 2 == self.count_checks(filters.have_name(r'\S*1|\S*3'))
assert 0 == self.count_checks(filters.have_name('Check'))
assert 3 == self.count_checks(filters.have_name('(?i)Check'))
assert 2 == self.count_checks(filters.have_name('(?i)check1|CHECK2'))

def test_have_not_name(self):
self.assertEqual(2, self.count_checks(filters.have_not_name('check1')))
self.assertEqual(
1, self.count_checks(filters.have_not_name('check1|check3'))
)
self.assertEqual(
0, self.count_checks(filters.have_not_name('check1|check2|check3'))
)
self.assertEqual(3, self.count_checks(filters.have_not_name('Check1')))
self.assertEqual(
2, self.count_checks(filters.have_not_name('(?i)Check1'))
)
assert 2 == self.count_checks(filters.have_not_name('check1'))
assert 1 == self.count_checks(filters.have_not_name('check1|check3'))
assert 0 == self.count_checks(filters.have_not_name(
'check1|check2|check3'))
assert 3 == self.count_checks(filters.have_not_name('Check1'))
assert 2 == self.count_checks(filters.have_not_name('(?i)Check1'))

def test_have_tags(self):
self.assertEqual(2, self.count_checks(filters.have_tag('a|c')))
self.assertEqual(0, self.count_checks(filters.have_tag('p|q')))
self.assertEqual(2, self.count_checks(filters.have_tag('z')))
assert 2 == self.count_checks(filters.have_tag('a|c'))
assert 0 == self.count_checks(filters.have_tag('p|q'))
assert 2 == self.count_checks(filters.have_tag('z'))

def test_have_prgenv(self):
self.assertEqual(
1, self.count_checks(filters.have_prgenv('env1|env2'))
)
self.assertEqual(2, self.count_checks(filters.have_prgenv('env3')))
self.assertEqual(1, self.count_checks(filters.have_prgenv('env4')))
self.assertEqual(
3, self.count_checks(filters.have_prgenv('env1|env3'))
)
assert 1 == self.count_checks(filters.have_prgenv('env1|env2'))
assert 2 == self.count_checks(filters.have_prgenv('env3'))
assert 1 == self.count_checks(filters.have_prgenv('env4'))
assert 3 == self.count_checks(filters.have_prgenv('env1|env3'))

@rt.switch_runtime(fixtures.TEST_SITE_CONFIG, 'testsys')
def test_partition(self):
p = rt.runtime().system.partition('gpu')
self.assertEqual(2, self.count_checks(filters.have_partition([p])))
assert 2 == self.count_checks(filters.have_partition([p]))
p = rt.runtime().system.partition('login')
self.assertEqual(0, self.count_checks(filters.have_partition([p])))
assert 0 == self.count_checks(filters.have_partition([p]))

def test_have_gpu_only(self):
self.assertEqual(2, self.count_checks(filters.have_gpu_only()))
assert 2 == self.count_checks(filters.have_gpu_only())

def test_have_cpu_only(self):
self.assertEqual(1, self.count_checks(filters.have_cpu_only()))
assert 1 == self.count_checks(filters.have_cpu_only())

def test_invalid_regex(self):
# We need to explicitly call `evaluate` to make sure the exception
# is triggered in all cases
with self.assertRaises(ReframeError):
with pytest.raises(ReframeError):
self.count_checks(filters.have_name('*foo')).evaluate()

with self.assertRaises(ReframeError):
with pytest.raises(ReframeError):
self.count_checks(filters.have_not_name('*foo')).evaluate()

with self.assertRaises(ReframeError):
with pytest.raises(ReframeError):
self.count_checks(filters.have_tag('*foo')).evaluate()

with self.assertRaises(ReframeError):
with pytest.raises(ReframeError):
self.count_checks(filters.have_prgenv('*foo')).evaluate()
Loading