[Django] #26795: Refactor code in tests.migrations.test_autodetector

5 views
Skip to first unread message

Django

unread,
Jun 23, 2016, 12:48:10 AM6/23/16
to django-...@googlegroups.com
#26795: Refactor code in tests.migrations.test_autodetector
--------------------------------------+--------------------
Reporter: akki | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Testing framework | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+--------------------
Recently, while working in
[https://github.com/django/django/blob/c2e62fd1aed093c4d9ff84e3d86e6a85c8aa1917/tests/migrations/test_autodetector.py
django.tests.migrations.test_autodetector] I noticed that the following
code is getting repeated approx 100 times:

{{{
#!python
before = self.make_project_state([self.author_name])
after = self.make_project_state([self.author_name_longer])
autodetector = MigrationAutodetector(before, after)
changes = autodetector._detect_changes()
}}}

I think it can be used as a simple method of the class cutting down a
large chunk of code. Something like:
{{{
#!python
def get_changes(self, before_states, after_states):
before = self.make_project_state([self.author_name])
after = self.make_project_state([self.author_name_longer])
autodetector = MigrationAutodetector(before, after)
return autodetector._detect_changes()
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/26795>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jun 23, 2016, 12:49:19 AM6/23/16
to django-...@googlegroups.com
#26795: Refactor code in tests.migrations.test_autodetector
-------------------------------------+-------------------------------------
Reporter: akki | Owner: nobody
Type: | Status: new
Cleanup/optimization |

Component: Testing framework | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by akki):

* needs_better_patch: => 0
* needs_tests: => 0
* easy: 0 => 1
* needs_docs: => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/26795#comment:1>

Django

unread,
Jun 23, 2016, 3:17:46 AM6/23/16
to django-...@googlegroups.com
#26795: Refactor code in tests.migrations.test_autodetector
-------------------------------------+-------------------------------------
Reporter: akki | Owner: nobody
Type: | Status: new
Cleanup/optimization |

Component: Testing framework | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by akki:

Old description:

> Recently, while working in
> [https://github.com/django/django/blob/c2e62fd1aed093c4d9ff84e3d86e6a85c8aa1917/tests/migrations/test_autodetector.py
> django.tests.migrations.test_autodetector] I noticed that the following
> code is getting repeated approx 100 times:
>
> {{{
> #!python
> before = self.make_project_state([self.author_name])
> after = self.make_project_state([self.author_name_longer])
> autodetector = MigrationAutodetector(before, after)
> changes = autodetector._detect_changes()
> }}}
>
> I think it can be used as a simple method of the class cutting down a
> large chunk of code. Something like:
> {{{
> #!python
> def get_changes(self, before_states, after_states):
> before = self.make_project_state([self.author_name])
> after = self.make_project_state([self.author_name_longer])
> autodetector = MigrationAutodetector(before, after)
> return autodetector._detect_changes()
> }}}

New description:

Recently, while working in
[https://github.com/django/django/blob/c2e62fd1aed093c4d9ff84e3d86e6a85c8aa1917/tests/migrations/test_autodetector.py
django.tests.migrations.test_autodetector] I noticed that the following
code is getting repeated approx 100 times:

{{{
#!python


before = self.make_project_state([self.author_name])
after = self.make_project_state([self.author_name_longer])
autodetector = MigrationAutodetector(before, after)
changes = autodetector._detect_changes()

}}}

I think it can be used as a simple method of the class cutting down a
large chunk of code. Something like:
{{{
#!python


def get_changes(self, before_states, after_states):
before = self.make_project_state([self.author_name])
after = self.make_project_state([self.author_name_longer])
autodetector = MigrationAutodetector(before, after)
return autodetector._detect_changes()

}}}

--

--
Ticket URL: <https://code.djangoproject.com/ticket/26795#comment:2>

Django

unread,
Jun 23, 2016, 10:18:58 AM6/23/16
to django-...@googlegroups.com
#26795: Factor out a "get_changes" method in tests.migrations.test_autodetector
--------------------------------------+------------------------------------

Reporter: akki | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by timgraham):

* component: Testing framework => Migrations
* stage: Unreviewed => Accepted


Old description:

> Recently, while working in
> [https://github.com/django/django/blob/c2e62fd1aed093c4d9ff84e3d86e6a85c8aa1917/tests/migrations/test_autodetector.py
> django.tests.migrations.test_autodetector] I noticed that the following
> code is getting repeated approx 100 times:
>
> {{{
> #!python
>

> before = self.make_project_state([self.author_name])
> after = self.make_project_state([self.author_name_longer])
> autodetector = MigrationAutodetector(before, after)
> changes = autodetector._detect_changes()
>
> }}}
>
> I think it can be used as a simple method of the class cutting down a
> large chunk of code. Something like:
> {{{
> #!python
>

> def get_changes(self, before_states, after_states):
> before = self.make_project_state([self.author_name])
> after = self.make_project_state([self.author_name_longer])
> autodetector = MigrationAutodetector(before, after)
> return autodetector._detect_changes()
>
> }}}

New description:

Recently, while working in
[https://github.com/django/django/blob/c2e62fd1aed093c4d9ff84e3d86e6a85c8aa1917/tests/migrations/test_autodetector.py
django.tests.migrations.test_autodetector] I noticed that the following
code is getting repeated approx 100 times:

{{{
#!python


before = self.make_project_state([self.author_name])
after = self.make_project_state([self.author_name_longer])
autodetector = MigrationAutodetector(before, after)
changes = autodetector._detect_changes()

}}}

I think it can be used as a simple method of the class cutting down a
large chunk of code. Something like:
{{{
#!python

def get_changes(self, before_states, after_states):
before = self.make_project_state(before_states)
after = self.make_project_state(after_states)


autodetector = MigrationAutodetector(before, after)
return autodetector._detect_changes()

}}}

--

--
Ticket URL: <https://code.djangoproject.com/ticket/26795#comment:3>

Django

unread,
Jun 23, 2016, 9:32:23 PM6/23/16
to django-...@googlegroups.com
#26795: Factor out a "get_changes" method in tests.migrations.test_autodetector
--------------------------------------+------------------------------------
Reporter: akki | Owner: akki
Type: Cleanup/optimization | Status: assigned

Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by akki):

* owner: nobody => akki
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/26795#comment:4>

Django

unread,
Jun 24, 2016, 3:11:22 PM6/24/16
to django-...@googlegroups.com
#26795: Factor out a "get_changes" method in tests.migrations.test_autodetector
-------------------------------------+-------------------------------------
Reporter: akki | Owner: akki
Type: | Status: assigned
Cleanup/optimization |

Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* has_patch: 0 => 1
* stage: Accepted => Ready for checkin


Comment:

[https://github.com/django/django/pull/6830 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/26795#comment:5>

Django

unread,
Jun 24, 2016, 9:45:43 PM6/24/16
to django-...@googlegroups.com
#26795: Factor out a "get_changes" method in tests.migrations.test_autodetector
-------------------------------------+-------------------------------------
Reporter: akki | Owner: akki
Type: | Status: closed

Cleanup/optimization |
Component: Migrations | Version: master
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"ca77b509059831b055a3b735ff77e042f8e1c0eb" ca77b509]:
{{{
#!CommitTicketReference repository=""
revision="ca77b509059831b055a3b735ff77e042f8e1c0eb"
Fixed #26795 -- Factored out get_changes() in test_autodetector.py.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/26795#comment:6>

Django

unread,
Jun 24, 2016, 10:10:36 PM6/24/16
to django-...@googlegroups.com
#26795: Factor out a "get_changes" method in tests.migrations.test_autodetector
-------------------------------------+-------------------------------------
Reporter: akki | Owner: akki
Type: | Status: closed
Cleanup/optimization |
Component: Migrations | Version: master
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"7f249e73dd9a44f2554d43df17617ab8f9dd0c46" 7f249e73]:
{{{
#!CommitTicketReference repository=""
revision="7f249e73dd9a44f2554d43df17617ab8f9dd0c46"
[1.10.x] Fixed #26795 -- Factored out get_changes() in
test_autodetector.py.

Backport of ca77b509059831b055a3b735ff77e042f8e1c0eb from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/26795#comment:7>

Reply all
Reply to author
Forward
0 new messages