def test_write_debug(): """ write_debug() method should return: 1. an error string containing the function where the bug occurred and the detailed message, no file if debuglog is unspecified 2. a file containing something similar to the above string is debuglog is a string """ filepath = os.path.join(configurator.default_path(), 'test_debug.log') # --- 1 --- result = config().write_debug(test_write_debug.__name__, "failed because reasons") assert_in("test_write_debug", result) assert_in("failed because reasons", result) assert_raises(FileNotFoundError, open, filepath, 'r') # --- 2 --- config().debuglog = "test_debug.log" config().write_debug(test_write_debug.__name__, "failed because reasons again") with open(filepath, 'r') as f: assert_in("failed because reasons again", f.read()) f.close()
def setup(): config().path_letters = configurator.default_path('test_cover-letters') config().file_type_letters = '.txt' dirpath = config().path_letters if not os.path.exists(dirpath): os.makedirs(dirpath) for letter in test_letterlist: with open(os.path.join(dirpath, letter[0]), 'w') as f: f.write(letter[1]) f.close()
def test_default_path(): """ default_path method should return: 1. if the 'path' kwarg is none, the path of the parent directory of configurator.py file 2. if the 'path' kwarg is a string, a path with a directory within the parent directory of configurator.py, named as the string 3. if the 'path' kwarg is an actual path, then it will return the same path """ base_path = os.path.dirname(os.path.abspath(configurator.__file__)) # --- 1 --- result_path = os.path.dirname(base_path) assert_equals(configurator.default_path(None), result_path) # --- 2 --- result_path = os.path.join(os.path.dirname(base_path), "test") assert_equals(configurator.default_path("test"), result_path) # --- 3 --- result_path = os.path.join(base_path, "cheese") assert_equals(configurator.default_path(result_path), result_path)
def teardown_test_write_debug(): filewalker.delete(configurator.default_path(), 'test_debug.log') config().debug = default_config.debug config().debuglog = default_config.debuglog
def setup_save_load(): config().path_letters = configurator.default_path("testletters") config().greeting = "GLaDOS"