Skip to content

Commit

Permalink
Merge pull request #3416 from boegel/test_flake8
Browse files Browse the repository at this point in the history
make flake8 code style checks pass in test/
  • Loading branch information
wpoely86 authored Aug 20, 2020
2 parents 9bc54d9 + 567beb2 commit 726d722
Show file tree
Hide file tree
Showing 33 changed files with 277 additions and 239 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ jobs:
- name: Run flake8
run: |
flake8 easybuild/tools
flake8 test/
6 changes: 3 additions & 3 deletions test/framework/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ def test_error_env_var_typo(self):
os.environ['EASYBUILD_THERESNOSUCHCONFIGURATIONOPTION'] = 'whatever'

error = r"Found 2 environment variable\(s\) that are prefixed with %s " % CONFIG_ENV_VAR_PREFIX
error += "but do not match valid option\(s\): "
error += ','.join(['EASYBUILD_FOO', 'EASYBUILD_THERESNOSUCHCONFIGURATIONOPTION'])
error += r"but do not match valid option\(s\): "
error += r','.join(['EASYBUILD_FOO', 'EASYBUILD_THERESNOSUCHCONFIGURATIONOPTION'])
self.assertErrorRegex(EasyBuildError, error, init_config)

del os.environ['EASYBUILD_THERESNOSUCHCONFIGURATIONOPTION']
Expand Down Expand Up @@ -365,7 +365,7 @@ def test_build_options(self):

# only valid keys can be set
BuildOptions.__class__._instances.clear()
msg = "Encountered unknown keys .* \(known keys: .*"
msg = r"Encountered unknown keys .* \(known keys: .*"
self.assertErrorRegex(KeyError, msg, BuildOptions, {'thisisclearlynotavalidbuildoption': 'FAIL'})

# test init_build_options and build_option functions
Expand Down
10 changes: 5 additions & 5 deletions test/framework/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ def test_end2end_singularity_image(self):
args.append('--container-tmpdir=%s' % self.test_prefix)
stdout, stderr = self.run_main(args)
self.assertFalse(stderr)
regexs[-3] = "^== Running 'sudo\s*SINGULARITY_TMPDIR=%s \S*/singularity build .*" % self.test_prefix
regexs[-3] = r"^== Running 'sudo\s*SINGULARITY_TMPDIR=%s \S*/singularity build .*" % self.test_prefix
self.check_regexs(regexs, stdout)

def test_end2end_dockerfile(self):
Expand Down Expand Up @@ -459,10 +459,10 @@ def test_end2end_docker_image(self):
stdout, stderr = self.run_main(args)
self.assertFalse(stderr)
regexs = [
"^== docker tool found at %s/bin/docker" % self.test_prefix,
"^== Dockerfile definition file created at %s/containers/Dockerfile\.toy-0.0" % self.test_prefix,
"^== Running 'sudo docker build -f .* -t .* \.', you may need to enter your 'sudo' password...",
"^== Docker image created at toy-0.0:latest",
r"^== docker tool found at %s/bin/docker" % self.test_prefix,
r"^== Dockerfile definition file created at %s/containers/Dockerfile\.toy-0.0" % self.test_prefix,
r"^== Running 'sudo docker build -f .* -t .* \.', you may need to enter your 'sudo' password...",
r"^== Docker image created at toy-0.0:latest",
]
self.check_regexs(regexs, stdout)

Expand Down
6 changes: 3 additions & 3 deletions test/framework/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def test_license_docs(self):
self.assertTrue(gplv3 in lic_docs, "%s found in: %s" % (gplv3, lic_docs))

lic_docs = avail_easyconfig_licenses(output_format='rst')
regex = re.compile("^``GPLv3``\s*The GNU General Public License", re.M)
regex = re.compile(r"^``GPLv3``\s*The GNU General Public License", re.M)
self.assertTrue(regex.search(lic_docs), "%s found in: %s" % (regex.pattern, lic_docs))

def test_list_software(self):
Expand Down Expand Up @@ -260,7 +260,7 @@ def test_list_software(self):
]
txt = list_software(output_format='txt', detailed=True)
lines = txt.split('\n')
expected_found = any([lines[i:i+len(expected)] == expected for i in range(len(lines))])
expected_found = any([lines[i:i + len(expected)] == expected for i in range(len(lines))])
self.assertTrue(expected_found, "%s found in: %s" % (expected, lines))

expected = [
Expand All @@ -283,7 +283,7 @@ def test_list_software(self):
]
txt = list_software(output_format='rst', detailed=True)
lines = txt.split('\n')
expected_found = any([lines[i:i+len(expected)] == expected for i in range(len(lines))])
expected_found = any([lines[i:i + len(expected)] == expected for i in range(len(lines))])
self.assertTrue(expected_found, "%s found in: %s" % (expected, lines))


Expand Down
6 changes: 3 additions & 3 deletions test/framework/easyblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ def test_make_module_extend_modpath(self):
elif get_module_syntax() == 'Lua':
regexs = [r'^prepend_path\("MODULEPATH", ".*/modules/funky/Compiler/pi/3.14/%s"\)$' % c for c in modclasses]
home = r'os.getenv\("HOME"\)'
pj_usermodsdir = 'pathJoin\("%s", "funky", "Compiler/pi/3.14"\)' % usermodsdir
pj_usermodsdir = r'pathJoin\("%s", "funky", "Compiler/pi/3.14"\)' % usermodsdir
regexs.extend([
# extension for user modules is guarded
r'if isDir\(pathJoin\(%s, %s\)\) then' % (home, pj_usermodsdir),
Expand Down Expand Up @@ -1061,7 +1061,7 @@ def test_make_module_step(self):

# [==[ or ]==] in description is fatal
if get_module_syntax() == 'Lua':
error_pattern = "Found unwanted '\[==\[' or '\]==\]' in: .*"
error_pattern = r"Found unwanted '\[==\[' or '\]==\]' in: .*"
for descr in ["test [==[", "]==] foo"]:
ectxt = read_file(self.eb_file)
write_file(self.eb_file, re.sub('description.*', 'description = "%s"' % descr, ectxt))
Expand Down Expand Up @@ -1263,7 +1263,7 @@ def test_fetch_sources(self):

# old format for specifying source with custom extract command is deprecated
eb.src = []
error_msg = "DEPRECATED \(since v4.0\).*Using a 2-element list/tuple.*"
error_msg = r"DEPRECATED \(since v4.0\).*Using a 2-element list/tuple.*"
self.assertErrorRegex(EasyBuildError, error_msg, eb.fetch_sources,
[('toy-0.0_gzip.patch.gz', "gunzip %s")], checksums=[])

Expand Down
48 changes: 24 additions & 24 deletions test/framework/easyconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,12 +558,12 @@ def test_tweaking(self):
homepage = "http://www.justatest.com"

tweaks = {
'version': ver,
'versionprefix': verpref,
'versionsuffix': versuff,
'toolchain_version': tcver,
'patches': new_patches
}
'version': ver,
'versionprefix': verpref,
'versionsuffix': versuff,
'toolchain_version': tcver,
'patches': new_patches
}
tweak_one(self.eb_file, tweaked_fn, tweaks)

eb = EasyConfig(tweaked_fn)
Expand Down Expand Up @@ -939,11 +939,11 @@ def trim_path(path):
def test_templating(self):
""" test easyconfig templating """
inp = {
'name': 'PI',
# purposely using minor version that starts with a 0, to check for correct version_minor value
'version': '3.04',
'namelower': 'pi',
'cmd': 'tar xfvz %s',
'name': 'PI',
# purposely using minor version that starts with a 0, to check for correct version_minor value
'version': '3.04',
'namelower': 'pi',
'cmd': 'tar xfvz %s',
}
# don't use any escaping insanity here, since it is templated itself
self.contents = '\n'.join([
Expand Down Expand Up @@ -1072,8 +1072,8 @@ def test_constant_doc(self):
doc = avail_easyconfig_constants()
# expected length: 1 per constant and 1 extra per constantgroup
temps = [
easyconfig.constants.EASYCONFIG_CONSTANTS,
]
easyconfig.constants.EASYCONFIG_CONSTANTS,
]
self.assertEqual(len(doc.split('\n')), sum([len(temps)] + [len(x) for x in temps]))

def test_build_options(self):
Expand Down Expand Up @@ -2259,17 +2259,17 @@ def test_dump_comments(self):

# check internal structure to keep track of comments
self.assertEqual(ec.parser._formatter.comments['above'], {
'dependencies': [
'# this is a multiline comment above dependencies',
'# I said multiline',
'# multi > 3',
],
'sanity_check_paths': ['# how about comments above and in a dict value?'],
'source_urls': ['# how about # a comment with # multple additional hashes'],
'sources': ['# after toolchain, before sources comment',
'',
'# this comment contains another #, uh-oh...'],
'version': ["# the version doesn't matter much here"],
'dependencies': [
'# this is a multiline comment above dependencies',
'# I said multiline',
'# multi > 3',
],
'sanity_check_paths': ['# how about comments above and in a dict value?'],
'source_urls': ['# how about # a comment with # multple additional hashes'],
'sources': ['# after toolchain, before sources comment',
'',
'# this comment contains another #, uh-oh...'],
'version': ["# the version doesn't matter much here"],
})
self.assertEqual(ec.parser._formatter.comments['header'], [
'# this is a header',
Expand Down
14 changes: 7 additions & 7 deletions test/framework/easyconfigversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ def test_versop_overlap_conflict(self):
('> 2 suffix:-x1', '< 1 suffix:-x1', (False, False)), # suffix equal, no conflict (and no overlap)
]

for l, r, res in overlap_conflict:
vl = VersionOperator(l)
vr = VersionOperator(r)
self.assertEqual(vl.test_overlap_and_conflict(vr), res)
for left, right, res in overlap_conflict:
verop_left = VersionOperator(left)
verop_right = VersionOperator(right)
self.assertEqual(verop_left.test_overlap_and_conflict(verop_right), res)

def test_versop_gt(self):
"""Test strict greater then ordering"""
Expand All @@ -135,8 +135,8 @@ def test_versop_gt(self):
# suffix
('> 2 suffix:-x1', '> 1 suffix:-x1'), # equal suffixes, regular ordering
]
for l, r in left_gt_right:
self.assertTrue(VersionOperator(l) > VersionOperator(r), "%s gt %s" % (l, r))
for left, right in left_gt_right:
self.assertTrue(VersionOperator(left) > VersionOperator(right), "%s gt %s" % (left, right))

def test_ordered_versop_expressions(self):
"""Given set of ranges, order them according to version/operator (most recent/specific first)"""
Expand Down Expand Up @@ -215,7 +215,7 @@ def test_toolchain_versop_test(self):
(tc, '1.2.2', False), # version not ok, name ok
('x' + tc, '1.2.3', False), # version ok, name not ok
('x' + tc, '1.2.2', False), # version not ok, name not ok
)),
)),
]
for txt, subtests in tests:
tcversop = ToolchainVersionOperator(txt)
Expand Down
7 changes: 3 additions & 4 deletions test/framework/filetools.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ def test_find_glob_pattern(self):
self.assertErrorRegex(EasyBuildError, "Was expecting exactly", ft.find_glob_pattern,
os.path.join(tmpdir, 'python*'))


def test_encode_class_name(self):
"""Test encoding of class names."""
for (class_name, encoded_class_name) in self.class_names:
Expand Down Expand Up @@ -929,7 +928,7 @@ def test_multidiff(self):
expected = "29 %s+ postinstallcmds = " % green
self.assertTrue(any([line.startswith(expected) for line in lines]))
expected = "30 %s+%s (1/2) toy-0.0" % (green, endcol)
self.assertTrue(any(l.startswith(expected) for l in lines), "Found '%s' in: %s" % (expected, lines))
self.assertTrue(any(line.startswith(expected) for line in lines), "Found '%s' in: %s" % (expected, lines))
self.assertEqual(lines[-1], "=====")

lines = multidiff(toy_ec, other_toy_ecs, colored=False).split('\n')
Expand All @@ -948,9 +947,9 @@ def test_multidiff(self):

# no postinstallcmds in toy-0.0-deps.eb
expected = "29 + postinstallcmds = "
self.assertTrue(any(l.startswith(expected) for l in lines), "Found '%s' in: %s" % (expected, lines))
self.assertTrue(any(line.startswith(expected) for line in lines), "Found '%s' in: %s" % (expected, lines))
expected = "30 + (1/2) toy-0.0-"
self.assertTrue(any(l.startswith(expected) for l in lines), "Found '%s' in: %s" % (expected, lines))
self.assertTrue(any(line.startswith(expected) for line in lines), "Found '%s' in: %s" % (expected, lines))

self.assertEqual(lines[-1], "=====")

Expand Down
6 changes: 3 additions & 3 deletions test/framework/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ def test_error_reporting(self):
easybuild_loc = os.path.dirname(os.path.dirname(os.path.abspath(easybuild.framework.__file__)))

log_method_regexes = [
re.compile("log\.error\("),
re.compile("log\.exception\("),
re.compile("log\.raiseException\("),
re.compile(r"log\.error\("),
re.compile(r"log\.exception\("),
re.compile(r"log\.raiseException\("),
]

for dirpath, _, filenames in os.walk(easybuild_loc):
Expand Down
16 changes: 9 additions & 7 deletions test/framework/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,11 @@ def test_walk(self):
return

try:
expected = [(None, ['a_directory', 'second_dir'], ['README.md']),
('a_directory', ['a_subdirectory'], ['a_file.txt']), ('a_directory/a_subdirectory', [],
['a_file.txt']), ('second_dir', [], ['a_file.txt'])]
expected = [
(None, ['a_directory', 'second_dir'], ['README.md']),
('a_directory', ['a_subdirectory'], ['a_file.txt']),
('a_directory/a_subdirectory', [], ['a_file.txt']), ('second_dir', [], ['a_file.txt']),
]
self.assertEqual([x for x in self.ghfs.walk(None)], expected)
except IOError:
pass
Expand Down Expand Up @@ -432,7 +434,7 @@ def test_find_easybuild_easyconfig(self):
print("Skipping test_find_easybuild_easyconfig, no GitHub token available?")
return
path = gh.find_easybuild_easyconfig(github_user=GITHUB_TEST_ACCOUNT)
expected = os.path.join('e', 'EasyBuild', 'EasyBuild-[1-9]+\.[0-9]+\.[0-9]+\.eb')
expected = os.path.join('e', 'EasyBuild', r'EasyBuild-[1-9]+\.[0-9]+\.[0-9]+\.eb')
regex = re.compile(expected)
self.assertTrue(regex.search(path), "Pattern '%s' found in '%s'" % (regex.pattern, path))
self.assertTrue(os.path.exists(path), "Path %s exists" % path)
Expand Down Expand Up @@ -618,9 +620,9 @@ def test_det_patch_specs(self):

patch_paths = [os.path.join(self.test_prefix, p) for p in ['1.patch', '2.patch', '3.patch']]
file_info = {'ecs': [
{'name': 'A', 'patches': ['1.patch'], 'exts_list': []},
{'name': 'B', 'patches': [], 'exts_list': []},
]
{'name': 'A', 'patches': ['1.patch'], 'exts_list': []},
{'name': 'B', 'patches': [], 'exts_list': []},
]
}
error_pattern = "Failed to determine software name to which patch file .*/2.patch relates"
self.mock_stdout(True)
Expand Down
2 changes: 1 addition & 1 deletion test/framework/include.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
def up(path, cnt):
"""Return path N times up."""
if cnt > 0:
path = up(os.path.dirname(path), cnt-1)
path = up(os.path.dirname(path), cnt - 1)
return path


Expand Down
12 changes: 6 additions & 6 deletions test/framework/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ def configure(self):
def test_run_cmd(self):
"""Test use of run_cmd function in the context of using EasyBuild framework as a library."""

error_pattern = "Undefined build option: .*"
error_pattern += " Make sure you have set up the EasyBuild configuration using set_up_configuration\(\)"
error_pattern = r"Undefined build option: .*"
error_pattern += r" Make sure you have set up the EasyBuild configuration using set_up_configuration\(\)"
self.assertErrorRegex(EasyBuildError, error_pattern, run_cmd, "echo hello")

self.configure()
Expand All @@ -95,8 +95,8 @@ def test_mkdir(self):

test_dir = os.path.join(self.tmpdir, 'test123')

error_pattern = "Undefined build option: .*"
error_pattern += " Make sure you have set up the EasyBuild configuration using set_up_configuration\(\)"
error_pattern = r"Undefined build option: .*"
error_pattern += r" Make sure you have set up the EasyBuild configuration using set_up_configuration\(\)"
self.assertErrorRegex(EasyBuildError, error_pattern, mkdir, test_dir)

self.configure()
Expand All @@ -109,8 +109,8 @@ def test_mkdir(self):
def test_modules_tool(self):
"""Test use of modules_tool function in the context of using EasyBuild framework as a library."""

error_pattern = "Undefined build option: .*"
error_pattern += " Make sure you have set up the EasyBuild configuration using set_up_configuration\(\)"
error_pattern = r"Undefined build option: .*"
error_pattern += r" Make sure you have set up the EasyBuild configuration using set_up_configuration\(\)"
self.assertErrorRegex(EasyBuildError, error_pattern, modules_tool)

self.configure()
Expand Down
8 changes: 4 additions & 4 deletions test/framework/module_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1327,11 +1327,11 @@ def test_ec(ecfile, short_modname, mod_subdir, modpath_exts, user_modpath_exts,
init_config(build_options=build_options)

test_ecs = {
'GCC-6.4.0-2.28.eb': ('compiler/GCC/6.4.0-2.28', '', [], [], []),
'GCC-6.4.0-2.28.eb': ('compiler/GCC/6.4.0-2.28', '', [], [], []),
'OpenMPI-2.1.2-GCC-6.4.0-2.28.eb': ('mpi/OpenMPI/2.1.2-GCC-6.4.0-2.28', '', [], [], []),
'gzip-1.5-foss-2018a.eb': ('tools/gzip/1.5-foss-2018a', '', [], [], []),
'foss-2018a.eb': ('toolchain/foss/2018a', '', [], [], []),
'impi-5.1.2.150.eb': ('mpi/impi/5.1.2.150', '', [], [], []),
'gzip-1.5-foss-2018a.eb': ('tools/gzip/1.5-foss-2018a', '', [], [], []),
'foss-2018a.eb': ('toolchain/foss/2018a', '', [], [], []),
'impi-5.1.2.150.eb': ('mpi/impi/5.1.2.150', '', [], [], []),
}
for ecfile, mns_vals in test_ecs.items():
test_ec(ecfile, *mns_vals)
Expand Down
8 changes: 4 additions & 4 deletions test/framework/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,10 +360,10 @@ def test_exist(self):
remove_file(os.path.join(java_mod_dir, '.modulerc'))
write_file(os.path.join(java_mod_dir, '.modulerc.lua'),
'\n'.join([
'module_version("Java/1.8.0_181", "1.8")',
'module_version("Java/1.8.0_181", "site_default")',
'module_alias("JavaAlias", "Java/1.8")',
]))
'module_version("Java/1.8.0_181", "1.8")',
'module_version("Java/1.8.0_181", "site_default")',
'module_alias("JavaAlias", "Java/1.8")',
]))

avail_mods = self.modtool.available()
self.assertTrue('Java/1.8.0_181' in avail_mods)
Expand Down
Loading

0 comments on commit 726d722

Please sign in to comment.