-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: change file type for graph file from pickle to JSON
- Loading branch information
1 parent
fa61feb
commit 5153293
Showing
4 changed files
with
98 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from __future__ import annotations | ||
|
||
import sys | ||
import time | ||
from pathlib import Path | ||
from textwrap import dedent | ||
|
||
import pytest | ||
from django.test import TestCase, override_settings | ||
|
||
from tests.utils import EMPTY_MIGRATION, run_command | ||
|
||
|
||
class RemakeMigrationsTests(TestCase): | ||
@pytest.fixture(autouse=True) | ||
def tmp_path_fixture(self, tmp_path): | ||
migrations_module_name = "migrations" + str(time.time()).replace(".", "") | ||
self.migrations_dir = tmp_path / migrations_module_name | ||
self.migrations_dir.mkdir() | ||
sys.path.insert(0, str(tmp_path)) | ||
try: | ||
with override_settings( | ||
MIGRATION_MODULES={"testapp": migrations_module_name} | ||
): | ||
yield | ||
finally: | ||
sys.path.pop(0) | ||
|
||
def test_success_step_1(self): | ||
(self.migrations_dir / "__init__.py").touch() | ||
initial_0001 = self.migrations_dir / "0001_initial.py" | ||
initial_0001.write_text(EMPTY_MIGRATION) | ||
migration_0002 = self.migrations_dir / "0002_something.py" | ||
migration_0002.write_text( | ||
dedent( | ||
"""\ | ||
from django.db import migrations | ||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
('testapp', '0001_initial'), | ||
] | ||
operations = [] | ||
""" | ||
) | ||
) | ||
|
||
out, err, returncode = run_command("remakemigrations", "--step", "1") | ||
|
||
assert out == "" | ||
assert err == "" | ||
assert returncode == 0 | ||
|
||
assert not initial_0001.exists() | ||
assert not migration_0002.exists() | ||
|
||
graph_json = Path(__file__).parent / "graph.json" | ||
assert graph_json.exists() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from __future__ import annotations | ||
|
||
from io import StringIO | ||
from textwrap import dedent | ||
|
||
from django.core.management import call_command | ||
|
||
|
||
def run_command(*args, **kwargs): | ||
out = StringIO() | ||
err = StringIO() | ||
return_code: int | str | None = 0 | ||
try: | ||
call_command(*args, stdout=out, stderr=err, **kwargs) | ||
except SystemExit as exc: # pragma: no cover | ||
return_code = exc.code | ||
return out.getvalue(), err.getvalue(), return_code | ||
|
||
|
||
EMPTY_MIGRATION = dedent( | ||
"""\ | ||
from django.db import migrations | ||
class Migration(migrations.Migration): | ||
pass | ||
""" | ||
) |