def test_stdout_unicode(capsys): if sys.version_info[0] == 2: msg = u"カイダーディー" else: msg = "カイダーディー" stdout(msg) out, err = capsys.readouterr() assert out == msg + "\n"
def test_stdout_unicode_flush_set_to_false(capsys): if sys.version_info[0] == 2: msg = u"カイダーディー" else: msg = "カイダーディー" stdout(msg, flush=False) out, err = capsys.readouterr() assert out == msg + "\n"
def test_stdout_ascii_reports_correct_statuscode_minusone(capsys): with pytest.raises(SystemExit): try: stdout("This is a test message", statuscode=-1) out, err = capsys.readouterr() assert out == "This is a test message\n" except SystemExit as exit_code: assert exit_code.__str__( ) == '-1' # tests the exit status code in the SystemExit exception raise exit_code
def test_stdout_end_parameter_test_false_unicode(capsys): with pytest.raises(TypeError): if sys.version_info[0] == 2: msg = u"カイダーディー" else: msg = "カイダーディー" end_str = 123 # define as an integer stdout(msg, end=end_str) out, err = capsys.readouterr() assert out == msg + end_str
def test_stdout_begin_parameter_test_true_unicode(capsys): if sys.version_info[0] == 2: msg = u"カイダーディー" beg_str = u'ディー ' else: msg = "カイダーディー" beg_str = 'ディー ' stdout(msg, begin=beg_str) out, err = capsys.readouterr() assert out == beg_str + msg + '\n'
def test_stdout_end_parameter_test_true_unicode(capsys): if sys.version_info[0] == 2: msg = u"カイダーディー" end_str = u'ディー' else: msg = "カイダーディー" end_str = 'ディー' stdout(msg, end=end_str) out, err = capsys.readouterr() assert out == msg + end_str
def test_stdout_unicode_end_parameter(capsys): if sys.version_info[0] == 2: msg = u"カイダーディー" else: msg = "カイダーディー" if sys.version_info[0] == 2: stdout(msg, end=u"==ディー==") else: stdout(msg, end="==ディー==") out, err = capsys.readouterr() if sys.version_info[0] == 2: assert out == u"カイダーディー==ディー==" else: assert out == "カイダーディー==ディー=="
def test_stdout_unicode_reports_correct_statuscode(capsys): if sys.version_info[0] == 2: msg = u"カイダーディー" else: msg = "カイダーディー" with pytest.raises(SystemExit): try: stdout(msg, statuscode=1) out, err = capsys.readouterr() assert out == msg + "\n" except SystemExit as exit_code: assert exit_code.__str__( ) == '1' # tests the exit status code in the SystemExit exception raise exit_code
def test_stdout_unicode_begin_parameter(capsys): if sys.version_info[0] == 2: msg = u"カイダーディー" else: msg = "カイダーディー" if sys.version_info[0] == 2: stdout(msg, begin=u"[ディー] ") else: stdout(msg, begin="[ディー] ") out, err = capsys.readouterr() if sys.version_info[0] == 2: assert out == u"[ディー] カイダーディー\n" else: assert out == "[ディー] カイダーディー\n"
def test_stdout_ascii_end_parameter(capsys): stdout("This is a test message", end="===>") out, err = capsys.readouterr() assert out == "This is a test message===>"
def test_stdout_msg_parameter_test_object_str_repr(capsys): bogus = BogusWithBoth() stdout(bogus) out, err = capsys.readouterr() assert out == "__str__ success\n" # defaults to __str__ method when both defined in class
def main(): """Defines the logic for the `ufodiff` command line executable""" c = Command() if c.does_not_validate_missing_args(): stderr( "[ufodiff] ERROR: Please include the appropriate arguments with your command." ) sys.exit(1) if c.is_help_request(): stdout(settings.HELP) sys.exit(0) elif c.is_version_request(): stdout(settings.VERSION) sys.exit(0) elif c.is_usage_request(): stdout(settings.USAGE) sys.exit(0) # DELTA + DELTAJSON + DELTAMD sub-commands if c.subcmd in {"delta", "deltajson", "deltamd"}: # argument validation validate_delta_commands_args(c) # create list for UFO filtered analyses as requested by user ufo_directory_list = [] for arg in c.argv: if arg.endswith(".ufo"): ufo_directory_list.append(arg) # flags for type of test is_branch_test = False is_commits_test = False if c.arg2.startswith("commits:"): is_commits_test = True commits_list = c.arg2.split(":") commit_number = commits_list[1] elif c.arg2.startswith("branch:"): is_branch_test = True branch_list = c.arg2.split(":") branch_name = branch_list[1] # else: # pass # TODO: add direct git idiom call support # recursive search for the root of the git repository x 3 levels if not found in working directory verified_gitroot_path = get_git_root_path() # perform the delta analysis on the repository, different object for commits vs branch tests if is_commits_test is True: delta = Delta( verified_gitroot_path, ufo_directory_list, is_commit_test=True, commit_number=commit_number, ) elif is_branch_test is True: delta = Delta( verified_gitroot_path, ufo_directory_list, is_branch_test=True, compare_branch_name=branch_name, ) if c.arg1 == "all": if c.subcmd == "delta": sys.stdout.write(delta.get_stdout_string(write_format="text")) elif c.subcmd == "deltajson": sys.stdout.write(delta.get_stdout_string(write_format="json")) elif c.subcmd == "deltamd": sys.stdout.write( delta.get_stdout_string(write_format="markdown")) # elif c.arg1 == "glyph": # pass # TODO: implement glyph only command handling with 'ufo delta glyph' # elif c.arg1 == "nonglyph": # pass # TODO: implement nonglyph only command handling with 'ufo delta nonglyph' # DIFF SUBCOMMAND elif c.subcmd == "diff": # argument validation validate_diff_commands_args(c) # execute the command try: verified_gitroot_path = get_git_root_path() diff = Diff(verified_gitroot_path, color_diff=True) for diff_string in diff.get_diff_string_generator(c.arg1): stdout(diff_string) except Exception as e: stderr( "[ufodiff] ERROR: Unable to excecute your request. Error returned as: " + os.linesep + str(e)) sys.exit(1) # DIFFNC SUBCOMMAND elif c.subcmd == "diffnc": # argument validations validate_diff_commands_args(c) # execute the command try: verified_gitroot_path = get_git_root_path() diff = Diff(verified_gitroot_path, color_diff=False) for diff_string in diff.get_diff_string_generator(c.arg1): stdout(diff_string) except Exception as e: stderr( "[ufodiff] ERROR: Unable to excecute your request. Error returned as: " + os.linesep + str(e)) sys.exit(1) # # DIFF-FILE SUBCOMMAND # elif c.subcmd == "diff-filter": # user specified file/directory filters on the diff performed # pass # # DIFF-FILENC SUBCOMMAND # elif c.subcmd == "diff-filternc": # pass sys.exit(0)
def test_stdout_ascii_flush_set_to_false(capsys): stdout("This is a test message", flush=False) out, err = capsys.readouterr() assert out == "This is a test message\n"
def test_stdout_ascii(capsys): stdout("This is a test message") out, err = capsys.readouterr() assert out == "This is a test message\n"
def test_stdout_missing_msg_parameter(capsys): with pytest.raises(TypeError): stdout() out, err = capsys.readouterr() assert out == "\n"
def test_stdout_statuscode_parameter_false(): with pytest.raises(TypeError): stdout("test string", statuscode="bad code")
def test_stdout_end_parameter_test_false_ascii(capsys): with pytest.raises(TypeError): stdout("This is a test message", end=123) out, err = capsys.readouterr() assert out == "[test] This is a test message..."
def test_stdout_end_parameter_test_true_ascii(capsys): stdout("This is a test message", end="...") out, err = capsys.readouterr() assert out == "This is a test message..."
def test_stdout_bad_object_as_statuscode(): with pytest.raises(NameError): stdout("This is a test message", statuscode=bogusobj)
def test_stdout_msg_parameter_test_nonstring_casts_ok(): stdout( str ) # confirm that string object casts to str without raising exception
def test_stdout_msg_parameter_test_object_nostr_norepr(capsys): bogus = Bogus() out, err = capsys.readouterr() stdout(bogus) # confirm that this does not raise exception
def test_stdout_begin_parameter_test_false_ascii(capsys): with pytest.raises(TypeError): stdout("This is a test message", begin=123) out, err = capsys.readouterr() assert out == "123This is a test message\n"
def test_stdout_msg_parameter_test_nonstring_cast_fails_nonexistent_object(): with pytest.raises(NameError): stdout(Fakeola)
def test_stdout_ascii_begin_parameter(capsys): stdout("This is a test message", begin="[test] ") out, err = capsys.readouterr() assert out == "[test] This is a test message\n"
def test_stdout_msg_parameter_test_object_nostr_repr(capsys): bogus = BogusWithRepr() stdout(bogus) out, err = capsys.readouterr() assert out == "__repr__ success\n"
def test_stdout_ascii_end_parameter_emptystring(capsys): stdout("This is a test message", end="") out, err = capsys.readouterr() assert out == "This is a test message"
def main(): """Defines the logic for the `font-line` command line executable""" c = Command() if c.does_not_validate_missing_args(): stderr("[font-line] ERROR: Please include one or more arguments with your command.") sys.exit(1) if c.is_help_request(): stdout(settings.HELP) sys.exit(0) elif c.is_version_request(): stdout(settings.VERSION) sys.exit(0) elif c.is_usage_request(): stdout(settings.USAGE) sys.exit(0) # REPORT sub-command if c.subcmd == "report": if c.argc < 2: stderr("[font-line] ERROR: Missing file path argument(s) after the report subcommand.") sys.exit(1) else: for fontpath in c.argv[1:]: # test for existence of file on path if file_exists(fontpath): # test that filepath includes file of a supported file type if is_supported_filetype(fontpath): stdout(get_font_report(fontpath)) else: stderr("[font-line] ERROR: '" + fontpath + "' does not appear to be a supported font file type.") else: stderr("[font-line] ERROR: '" + fontpath + "' does not appear to be a valid filepath.") # PERCENT sub-command elif c.subcmd == "percent": if c.argc < 3: stderr("[font-line] ERROR: Not enough arguments.") sys.exit(1) else: percent = c.argv[1] # test the percent integer argument try: percent_int = int(percent) # test that the argument can be cast to an integer value if percent_int <= 0: stderr("[font-line] ERROR: Please enter a percent value that is greater than zero.") sys.exit(1) if percent_int > 100: stdout("[font-line] Warning: You entered a percent value over 100%. Please confirm that this is " "your intended metrics modification.") except ValueError: stderr("[font-line] ERROR: You entered '" + percent + "'. This argument needs to be an integer value.") sys.exit(1) for fontpath in c.argv[2:]: if file_exists(fontpath): if is_supported_filetype(fontpath): if modify_linegap_percent(fontpath, percent) is True: outpath = get_linegap_percent_filepath(fontpath, percent) stdout("[font-line] '" + fontpath + "' successfully modified to '" + outpath + "'.") else: # pragma: no cover stderr("[font-line] ERROR: Unsuccessful modification of '" + fontpath + "'.") else: stderr("[font-line] ERROR: '" + fontpath + "' does not appear to be a supported font file type.") else: stderr("[font-line] ERROR: '" + fontpath + "' does not appear to be a valid filepath.") else: stderr("[font-lines] ERROR: You used an unsupported argument to the executable. Please review the" " `font-line --help` documentation and try again.") sys.exit(1)
def main(): """Defines the logic for the `font-line` command line executable""" c = Command() if c.does_not_validate_missing_args(): stderr( "[font-line] ERROR: Please include one or more arguments with your command." ) sys.exit(1) if c.is_help_request(): stdout(settings.HELP) sys.exit(0) elif c.is_version_request(): stdout(settings.VERSION) sys.exit(0) elif c.is_usage_request(): stdout(settings.USAGE) sys.exit(0) # REPORT sub-command if c.subcmd == "report": if c.argc < 2: stderr( "[font-line] ERROR: Missing file path argument(s) after the " "report subcommand.") sys.exit(1) else: for fontpath in c.argv[1:]: # test for existence of file on path if file_exists(fontpath): # test that filepath includes file of a supported file type if is_supported_filetype(fontpath): stdout(get_font_report(fontpath)) else: stderr( "[font-line] ERROR: '" + fontpath + "' does not appear to be a supported font file type." ) else: stderr("[font-line] ERROR: '" + fontpath + "' does not appear to be a valid filepath.") # PERCENT sub-command elif c.subcmd == "percent": if c.argc < 3: stderr("[font-line] ERROR: Not enough arguments.") sys.exit(1) else: percent = c.argv[1] # test the percent integer argument try: percent_int = int( percent ) # test that the argument can be cast to an integer value if percent_int <= 0: stderr( "[font-line] ERROR: Please enter a percent value that is " "greater than zero.") sys.exit(1) if percent_int > 100: stdout( "[font-line] Warning: You entered a percent value over 100%. " "Please confirm that this is your intended metrics modification." ) except ValueError: stderr("[font-line] ERROR: You entered '" + percent + "'. This argument needs to be an integer value.") sys.exit(1) for fontpath in c.argv[2:]: if file_exists(fontpath): if is_supported_filetype(fontpath): if modify_linegap_percent(fontpath, percent) is True: outpath = get_linegap_percent_filepath( fontpath, percent) stdout("[font-line] '" + fontpath + "' successfully modified to '" + outpath + "'.") else: # pragma: no cover stderr( "[font-line] ERROR: Unsuccessful modification of '" + fontpath + "'.") else: stderr( "[font-line] ERROR: '" + fontpath + "' does not appear to be a supported font file type." ) else: stderr("[font-line] ERROR: '" + fontpath + "' does not appear to be a valid filepath.") else: stderr( "[font-lines] ERROR: You used an unsupported argument to the executable. " "Please review the `font-line --help` documentation and try again." ) sys.exit(1)