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 teardown_save_load(): filewalker.delete(config()._path_config, [config()._name_config, config()._name_config+'.temp', ]) config().path_letters = default_config.path_letters config().greeting = default_config.greeting
def teardown(): """ if the config directory had to be made just for this test, remove it """ if not os.listdir(config()._path_config): os.removedirs(config()._path_config)
def test_get_list(): """ get_list() should return a list of all of the cover letters within the path specified by path_letters in the Config object """ result = filewalker.get_list(config().path_letters, config().file_type_letters) assert_equals(result, test_letternamelist)
def test_load_dict(): """ load_dict method should save the following into the Config object: 1. a dict containing a key 'path_letters' should save its value into the object's attribute with the matching name. 2. a dict containing a key that's not an attribute shouldn't save into the Config() object 3. both 1 and 2 combined should still work as the method should just omit 2's input """ # --- 1 --- test_dict = {'path_letters': os.path.abspath(configurator.__file__)} config()._load_dict(test_dict) assert_equals(config().path_letters, test_dict['path_letters']) # --- 2 --- test_dict2 = {'shouldntexist': "butts"} config()._load_dict(test_dict2) assert_equals(hasattr(config, 'shouldntexist'), False) # --- 3 --- config().path_letters = default_config.path_letters test_dict = {**test_dict, **test_dict2} config()._load_dict(test_dict) assert_equals(hasattr(config, 'shouldntexist'), False) assert_equals(config().path_letters, test_dict['path_letters'])
def teardown(): dirpath = config().path_letters for letter in test_letterlist: filewalker.delete(dirpath, letter[0]) if not os.listdir(dirpath): os.removedirs(dirpath) config().path_letters = default_config().path_letters config().file_type_letters = default_config().file_type_letters
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_save_load(): """ Config should save all attributes and values as a dict into a json file and then be read back into the config object. If save(force=False) then a FileExistsError exception should be raised if the save was already done. """ config().save() result_config = configurator.Config.load() assert_equals(result_config.path_letters, config().path_letters) assert_equals(result_config.greeting, config().greeting) assert_raises(FileExistsError, config().save, force=False)
def teardown_load_dict(): if hasattr(config, 'shouldntexist'): del config().shouldntexist
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_test_write_debug(): config().debug = True
def setup_save_load(): config().path_letters = configurator.default_path("testletters") config().greeting = "GLaDOS"
from CoverLetterExpress import menu from CoverLetterExpress import utility from CoverLetterExpress import configurator from CoverLetterExpress.configurator import get_config as config continue_msg = False utility.clear_screen() print("Initializing setup...") # attempt to load a previously save config try: configurator.set_config(configurator.Config.load()) except FileNotFoundError: print("No config was found, making one...") config().save(force=False) continue_msg = True print("\nSetup complete!") if continue_msg: input(config().continue_msg) menu.hub_navigation()
import os from CoverLetterExpress import filewalker from CoverLetterExpress import configurator from nose.tools import * from CoverLetterExpress.configurator import get_config as config test_lettername1 = ['test_awesomecompany' + config().file_type_letters, "I think {company} is great!\n\n\nSincerely,\nMe", ] test_lettername2 = ['test_throwaway' + config().file_type_letters, "That's why I'm dah BESTEST!", ] test_lettername3 = ['test_shouldntwork' + config().file_type_letters+'2', "Dear {greeting},\n\nI got nothing.", ] test_letterlist = [test_lettername1, test_lettername2, test_lettername3, ] test_letternamelist = [test_lettername1[0], test_lettername2[0], ] default_config = configurator.Config def setup(): config().path_letters = configurator.default_path('test_cover-letters') config().file_type_letters = '.txt'