Check-in [a58cf2a418]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Revise nested functions in utilities.py module file_diff() function to handle line pairs with unequal number of tokens.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:a58cf2a4188a33cf525e67f4ad1294f221622759
User & Date: mrh 2015-06-02 15:21:08
Context
2015-06-15
18:27
Change "Open-Source Policy Center" to "Open Source Policy Center" to be consistent with the OSPC GitHub website. check-in: c262fb4e8c user: mrh tags: trunk
2015-06-02
15:21
Revise nested functions in utilities.py module file_diff() function to handle line pairs with unequal number of tokens. check-in: a58cf2a418 user: mrh tags: trunk
04:27
Revise write_significant_line_diff() function nested in file_diff() function in the utilities.py import module so that it writes a line pair with difference(s) only once. check-in: 671a71a887 user: mrh tags: trunk
Changes

Changes to utilities.py.

114
115
116
117
118
119
120
121
122
123
124





125
126
127
128





129




130
131
132
133
134
135
136
137
138
139
140
141
142
143
144

    def write_significant_line_diff(act_line, exp_line):
        """Write act_line and exp_line to stdout if a significant difference.

        Expects the two lines to have the same number of whitespace-separated
        tokens that can be interpreted as floating-point numbers.

        The tolerance parameter, which is a parameter of the nesting
        function, specifies the largest absolute-value difference
        between corresponding tokens that is considered insignificant.
        """





        for act_tok, exp_tok in zip(act_line.split(None), exp_line.split(None)):
            if act_tok != exp_tok:
                abs_diff = round(abs(float(act_tok) - float(exp_tok)), 10)
                if abs_diff > tolerance:





                    # write modified act_line and exp_line to stdout




                    line = act_line.replace('!', (act_filename + ':\n'), 1)
                    sys.stdout.write(line + '\n')
                    line = exp_line.replace('!', (exp_filename + ':\n'), 1)
                    sys.stdout.write(line + '\n')
                    line = '----------------------------------------------'
                    sys.stdout.write(line + '\n')
                    break # write line pair with diff only once
    # end of write_significant_line_diff code
    # ... end of nested functions code

    # write only significant differences to stdout
    diff_list = all_diffs_string.split('***************\n')
    for diff in diff_list[1:]: # skip header item in diff_list
        process_diff_block(diff)
# end of file_diff function code







|



>
>
>
>
>
|



>
>
>
>
>
|
>
>
>
>
|
|
|
|
|
|
<
|







114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149

150
151
152
153
154
155
156
157

    def write_significant_line_diff(act_line, exp_line):
        """Write act_line and exp_line to stdout if a significant difference.

        Expects the two lines to have the same number of whitespace-separated
        tokens that can be interpreted as floating-point numbers.

        The tolerance parameter, which is a parameter of a nesting
        function, specifies the largest absolute-value difference
        between corresponding tokens that is considered insignificant.
        """
        act_line_token_list = act_line.split(None)
        exp_line_token_list = exp_line.split(None)
        if len(act_line_token_list) != len(exp_line_token_list):
            write_line_pair_with_diff(act_line, exp_line)
            return # write line pair with unequal number of tokens only once
        for act_tok, exp_tok in zip(act_line_token_list, exp_line_token_list):
            if act_tok != exp_tok:
                abs_diff = round(abs(float(act_tok) - float(exp_tok)), 10)
                if abs_diff > tolerance:
                    write_line_pair_with_diff(act_line, exp_line)
                    return # write line pair with token difference(s) only once
    # end of write_significant_line_diff code

    def write_line_pair_with_diff(act_line, exp_line):
        """Write modified act_line and exp_line to stdout.

        The act_filename and exp_filename parameters are parameters
        of a nesting function.
        """
        line = act_line.replace('!', (act_filename + ':\n'), 1)
        sys.stdout.write(line + '\n')
        line = exp_line.replace('!', (exp_filename + ':\n'), 1)
        sys.stdout.write(line + '\n')
        line = '----------------------------------------------'
        sys.stdout.write(line + '\n')

    # end of write_line_pair_with_diff code
    # ... end of nested functions code

    # write only significant differences to stdout
    diff_list = all_diffs_string.split('***************\n')
    for diff in diff_list[1:]: # skip header item in diff_list
        process_diff_block(diff)
# end of file_diff function code