Skip to content

Conversation

@dhermes
Copy link
Contributor

@dhermes dhermes commented Jul 19, 2017

Any usage of self.assertTrue(a is b) has become self.assertIs(a, b).

I used a Python script to make this change:

# Produce file via
# $ git grep -n assertTrue | grep ' is ' > change_it.txt
# Manually made changes for lines with 12 space indent and for
# the files in the Speech package

import collections

def main():
    with open('change_it.txt', 'r') as file_obj:
        lines = file_obj.read().strip().split('\n')

    by_file = collections.defaultdict(dict)
    for line in lines:
        filename, line_no, content = line.split(':')
        line_no = int(line_no)
        in_file = by_file[filename]
        if line_no in in_file:
            raise KeyError('WAT', filename, line_no)
        if content[:24] != '        self.assertTrue(':
            raise ValueError(line, 'bad 1')
        if content[-1] != ')':
            raise ValueError(line, 'bad 2')
        left, right = content[24:-1].split(' is ')
        if ' ' in left or ' ' in right:
            raise ValueError(line, 'bad 3')

        actual = '        self.assertIs({}, {})'.format(left, right)
        in_file[line_no] = (content, actual)

    for filename, in_file in by_file.items():
        with open(filename, 'r') as file_obj:
            lines = file_obj.read().split('\n')

        for line_no, pair in in_file.items():
            assert lines[line_no - 1] == pair[0]
            lines[line_no - 1] = pair[1]

        with open(filename, 'w') as file_obj:
            file_obj.write('\n'.join(lines))


if __name__ == '__main__':
    main()

Any usage of `self.assertTrue(a is b)` has become
`self.assertIs(a, b)`.
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Jul 19, 2017
@dhermes dhermes merged commit 34bf003 into googleapis:master Jul 19, 2017
@dhermes dhermes deleted the use-assertIs branch July 19, 2017 21:44
landrito pushed a commit to landrito/google-cloud-python that referenced this pull request Aug 21, 2017
* Using assertIs in unit tests where appropriate.

Any usage of `self.assertTrue(a is b)` has become
`self.assertIs(a, b)`.

* Converting some assertFalse(a is b) to assertIsNot(a, b).
landrito pushed a commit to landrito/google-cloud-python that referenced this pull request Aug 22, 2017
* Using assertIs in unit tests where appropriate.

Any usage of `self.assertTrue(a is b)` has become
`self.assertIs(a, b)`.

* Converting some assertFalse(a is b) to assertIsNot(a, b).
landrito pushed a commit to landrito/google-cloud-python that referenced this pull request Aug 22, 2017
* Using assertIs in unit tests where appropriate.

Any usage of `self.assertTrue(a is b)` has become
`self.assertIs(a, b)`.

* Converting some assertFalse(a is b) to assertIsNot(a, b).
atulep pushed a commit that referenced this pull request Apr 3, 2023
* Using assertIs in unit tests where appropriate.

Any usage of `self.assertTrue(a is b)` has become
`self.assertIs(a, b)`.

* Converting some assertFalse(a is b) to assertIsNot(a, b).
atulep pushed a commit that referenced this pull request Apr 18, 2023
* Using assertIs in unit tests where appropriate.

Any usage of `self.assertTrue(a is b)` has become
`self.assertIs(a, b)`.

* Converting some assertFalse(a is b) to assertIsNot(a, b).
parthea pushed a commit that referenced this pull request Oct 22, 2023
* Using assertIs in unit tests where appropriate.

Any usage of `self.assertTrue(a is b)` has become
`self.assertIs(a, b)`.

* Converting some assertFalse(a is b) to assertIsNot(a, b).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes This human has signed the Contributor License Agreement. testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants