-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1448 from pyiron/replace_deprecated_disutils
Replace copy_tree from distutils by copytree from shutil because dist…
- Loading branch information
Showing
4 changed files
with
61 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# coding: utf-8 | ||
# Copyright (c) Max-Planck-Institut für Eisenforschung GmbH - Computational Materials Design (CM) Department | ||
# Distributed under the terms of "New BSD License", see the LICENSE file. | ||
|
||
""" | ||
Utility functions used in pyiron. | ||
In order to be accessible from anywhere in pyiron, they *must* remain free of | ||
any imports from pyiron! | ||
""" | ||
|
||
__author__ = "Joerg Neugebauer, Jan Janssen" | ||
__copyright__ = ( | ||
"Copyright 2020, Max-Planck-Institut für Eisenforschung GmbH - " | ||
"Computational Materials Design (CM) Department" | ||
) | ||
__version__ = "1.0" | ||
__maintainer__ = "Jan Janssen" | ||
__email__ = "janssen@mpie.de" | ||
__status__ = "production" | ||
__date__ = "Sep 1, 2017" | ||
|
||
|
||
def strtobool(val: str): | ||
"""Convert a string representation of truth to true (1) or false (0). | ||
True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values | ||
are 'n', 'no', 'f', 'false', 'off', and '0'. Raises ValueError if | ||
'val' is anything else. | ||
Originally part of `distutils.util.strtobool`, but copied and pasted as | ||
`distutils` was going to be removed from python 3.12. | ||
""" | ||
val = val.lower() | ||
if val in ("y", "yes", "t", "true", "on", "1"): | ||
return 1 | ||
elif val in ("n", "no", "f", "false", "off", "0"): | ||
return 0 | ||
else: | ||
raise ValueError("invalid truth value %r" % (val,)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import unittest | ||
|
||
from pyiron_base.utils.strtobool import strtobool | ||
|
||
|
||
class TestStrtobool(unittest.TestCase): | ||
def test_letters(self): | ||
for val in ("y", "yes", "t", "true", "on", "1"): | ||
self.assertTrue(strtobool(val)) | ||
for val in ("Y", "YEs", "T", "tRue", "oN", "1"): | ||
self.assertTrue(strtobool(val)) | ||
for val in ("n", "no", "f", "false", "off", "0"): | ||
self.assertFalse(strtobool(val)) | ||
with self.assertRaises(ValueError): | ||
strtobool("Vegetarians do not eat Bratwurst") | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |