-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for current package to codemod context.
- Loading branch information
1 parent
f6a1c77
commit c21ae59
Showing
3 changed files
with
92 additions
and
2 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,46 @@ | ||
# Copyright (c) Facebook, Inc. and its affiliates. | ||
# | ||
# This source code is licensed under the MIT license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
# | ||
# pyre-strict | ||
from typing import Optional | ||
|
||
from libcst.codemod._cli import _calculate_module | ||
from libcst.testing.utils import UnitTest, data_provider | ||
|
||
|
||
class TestPackageCalculation(UnitTest): | ||
@data_provider( | ||
( | ||
# Providing no root should give back no module. | ||
(None, "/some/dummy/file.py", None), | ||
# Providing a file outside the root should give back no module. | ||
("/home/username/root", "/some/dummy/file.py", None), | ||
("/home/username/root/", "/some/dummy/file.py", None), | ||
("/home/username/root", "/home/username/file.py", None), | ||
# Various files inside the root should give back valid modules. | ||
("/home/username/root", "/home/username/root/file.py", "file"), | ||
("/home/username/root/", "/home/username/root/file.py", "file"), | ||
( | ||
"/home/username/root/", | ||
"/home/username/root/some/dir/file.py", | ||
"some.dir.file", | ||
), | ||
# Various special files inside the root should give back valid modules. | ||
( | ||
"/home/username/root/", | ||
"/home/username/root/some/dir/__init__.py", | ||
"some.dir", | ||
), | ||
( | ||
"/home/username/root/", | ||
"/home/username/root/some/dir/__main__.py", | ||
"some.dir", | ||
), | ||
), | ||
) | ||
def test_calculate_module( | ||
self, repo_root: Optional[str], filename: str, module: str | ||
) -> None: | ||
self.assertEqual(_calculate_module(repo_root, filename), module) |