Skip to content

Commit

Permalink
fix: test scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
magic-akari committed Jan 14, 2024
1 parent 348112e commit 3f1c449
Show file tree
Hide file tree
Showing 15 changed files with 165 additions and 514 deletions.
9 changes: 6 additions & 3 deletions crates/ruff_fmt/src/test.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
#[cfg(test)]
mod tests {
use std::{fs::File, io::Read, path::PathBuf};
use std::{fs::File, io::Read, path::PathBuf, str::FromStr};
use testing_macros::fixture;

use crate::format;

#[fixture("test_data/*.input")]
#[fixture("test_data/**/*.py")]
#[fixture("test_data/**/*.pyi")]
fn it_works(input: PathBuf) {
// calc the expected file path
let extect_path = input.with_extension("expect");
let input = input.clone();
let extect_path = input.to_string_lossy() + ".expect";
let extect_path = PathBuf::from_str(&extect_path).unwrap();

let mut actual = String::new();
File::open(&input).and_then(|mut file| file.read_to_string(&mut actual)).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff_fmt/test_bun/bun.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ for await (const input_path of walk(test_root)) {
]);

test(test_name, () => {
const actual = format(input);
const actual = format(input, input_path);
expect(actual).toBe(expected);
});
}
12 changes: 2 additions & 10 deletions crates/ruff_fmt/test_data/black/cases/ignore_pyi.pyi.expect
Original file line number Diff line number Diff line change
@@ -1,25 +1,17 @@
def f(): # type: ignore
...


class x: # some comment
...


class y:
... # comment

class y: ... # comment

# whitespace doesn't matter (note the next line has a trailing space and tab)
class z:
...

class z: ...

def g():
# hi
...


def h():
...
# bye
37 changes: 7 additions & 30 deletions crates/ruff_fmt/test_data/black/cases/nested_stub.pyi.expect
Original file line number Diff line number Diff line change
@@ -1,52 +1,29 @@
import sys


class Outer:
class InnerStub:
...

class InnerStub: ...
outer_attr_after_inner_stub: int

class Inner:
inner_attr: int

outer_attr: int


if sys.version_info > (3, 7):
if sys.platform == "win32":
assignment = 1

def function_definition(self):
...

def f1(self) -> str:
...

def function_definition(self): ...
def f1(self) -> str: ...
if sys.platform != "win32":

def function_definition(self):
...

def function_definition(self): ...
assignment = 1

def f2(self) -> str:
...

def f2(self) -> str: ...

class TopLevel:
class Nested1:
foo: int

def bar(self):
...

def bar(self): ...
field = 1

class Nested2:
def bar(self):
...

def bar(self): ...
foo: int

field = 1
134 changes: 32 additions & 102 deletions crates/ruff_fmt/test_data/black/cases/stub.pyi.expect
Original file line number Diff line number Diff line change
@@ -1,133 +1,63 @@
X: int

def f(): ...

def f():
...


class D:
...


class C:
...

class D: ...
class C: ...

class B:
this_lack_of_newline_should_be_kept: int

def b(self) -> None:
...
def b(self) -> None: ...

but_this_newline_should_also_be_kept: int


class A:
attr: int
attr2: str

def f(self) -> int:
...

def g(self) -> str:
...


def g():
...


def h():
...
def f(self) -> int: ...
def g(self) -> str: ...

def g(): ...
def h(): ...

if sys.version_info >= (3, 8):

class E:
def f(self):
...

def f(self): ...
class F:
def f(self):
...

class G:
...

class H:
...
def f(self): ...
class G: ...
class H: ...
else:

class I:
...

class J:
...

def f():
...
class I: ...
class J: ...
def f(): ...

class K:
def f(self):
...

def f():
...

def f(self): ...
def f(): ...

class Nested:
class dirty:
...

class little:
...

class dirty: ...
class little: ...
class secret:
def who_has_to_know(self):
...

def verse(self):
...

def who_has_to_know(self): ...
def verse(self): ...

class Conditional:
def f(self):
...

def f(self): ...
if sys.version_info >= (3, 8):

def g(self):
...
def g(self): ...
else:

def g(self):
...

def h(self):
...

def i(self):
...

def g(self): ...
def h(self): ...
def i(self): ...
if sys.version_info >= (3, 8):

def j(self):
...

def k(self):
...

def j(self): ...
def k(self): ...
if sys.version_info >= (3, 8):

class A:
...

class B:
...

class A: ...
class B: ...
class C:
def l(self):
...

def m(self):
...
def l(self): ...
def m(self): ...
51 changes: 12 additions & 39 deletions crates/ruff_fmt/test_data/black/miscellaneous/force_pyi.pyi.expect
Original file line number Diff line number Diff line change
@@ -1,58 +1,31 @@
from typing import Union


@bird
def zoo():
...


class A:
...
def zoo(): ...

class A: ...

@bar
class B:
def BMethod(self) -> None:
...

def BMethod(self) -> None: ...
@overload
def BMethod(self, arg: List[str]) -> None:
...


class C:
...
def BMethod(self, arg: List[str]) -> None: ...

class C: ...

@hmm
class D:
...


class E:
...

class D: ...
class E: ...

@baz
def foo() -> None:
...


class F(A, C):
...


def spam() -> None:
...
def foo() -> None: ...

class F(A, C): ...

def spam() -> None: ...
@overload
def spam(arg: str) -> str:
...

def spam(arg: str) -> str: ...

var: int = 1


def eggs() -> Union[str, int]:
...
def eggs() -> Union[str, int]: ...
Loading

0 comments on commit 3f1c449

Please sign in to comment.