Skip to content

Commit

Permalink
[mojo-stdlib] Import what you use rather than from <module> import * (
Browse files Browse the repository at this point in the history
modularml#2081)

Change the tests to explicitly import what they use rather than using `from <module> import *`.

Signed-off-by: Kaushal Phulgirkar <[email protected]>
  • Loading branch information
StandinKP authored and helehex committed Apr 6, 2024
1 parent 4eb6495 commit 6a9cd0a
Show file tree
Hide file tree
Showing 29 changed files with 63 additions and 33 deletions.
22 changes: 20 additions & 2 deletions examples/deviceinfo.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,26 @@

# This sample prints the current host system information using APIs from the
# sys module.
from sys.info import *
from sys.info import _current_cpu, _current_target, _triple_attr
from sys.info import (
_current_cpu,
_current_target,
_triple_attr,
os_is_linux,
os_is_macos,
os_is_windows,
has_sse4,
has_avx,
has_avx2,
has_avx512f,
has_vnni,
has_intel_amx,
has_neon,
is_apple_m1,
is_apple_m2,
is_apple_m3,
num_physical_cores,
num_logical_cores,
)


def main():
Expand Down
2 changes: 1 addition & 1 deletion stdlib/test/builtin/test_bfloat16.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from random import randn_float64
from sys.info import has_neon

from testing import *
from testing import assert_equal, assert_almost_equal


def test_methods():
Expand Down
2 changes: 1 addition & 1 deletion stdlib/test/builtin/test_dtype.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from collections import Set

from testing import *
from testing import assert_equal, assert_false, assert_true


fn test_stringable() raises:
Expand Down
2 changes: 1 addition & 1 deletion stdlib/test/builtin/test_hash.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# specific. But for now they test behavior and reproducibility.

from builtin.hash import _hash_simd
from testing import *
from testing import assert_equal, assert_not_equal, assert_true


def same_low_bits(i1: Int, i2: Int, bits: Int = 4) -> Int:
Expand Down
2 changes: 1 addition & 1 deletion stdlib/test/builtin/test_int.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# ===----------------------------------------------------------------------=== #
# RUN: %mojo -debug-level full %s

from testing import *
from testing import assert_equal


def test_constructors():
Expand Down
2 changes: 1 addition & 1 deletion stdlib/test/builtin/test_issue_1505.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from random import random_ui64

from testing import *
from testing import assert_equal


fn gen_perm() -> StaticIntTuple[64]:
Expand Down
2 changes: 1 addition & 1 deletion stdlib/test/builtin/test_location.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# RUN: mojo --debug-level full %s

from builtin._location import _SourceLocation
from testing import *
from testing import assert_equal


def main():
Expand Down
2 changes: 1 addition & 1 deletion stdlib/test/builtin/test_simd.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from sys.info import has_neon, simdwidthof

from testing import *
from testing import assert_equal, assert_not_equal, assert_true


# CHECK-LABEL: test_cast
Expand Down
2 changes: 1 addition & 1 deletion stdlib/test/builtin/test_slice.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# ===----------------------------------------------------------------------=== #
# RUN: %mojo -debug-level full %s | FileCheck %s

from testing import *
from testing import assert_equal, assert_false


# CHECK-LABEL: test_none_end_folds
Expand Down
2 changes: 1 addition & 1 deletion stdlib/test/builtin/test_str.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# ===----------------------------------------------------------------------=== #
# RUN: %mojo -debug-level full %s

from testing import *
from testing import assert_equal


def test_str_none():
Expand Down
8 changes: 7 additions & 1 deletion stdlib/test/builtin/test_string.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ from builtin.string import (
_calc_initial_buffer_size_int32,
_calc_initial_buffer_size_int64,
)
from testing import *
from testing import (
assert_equal,
assert_false,
assert_not_equal,
assert_raises,
assert_true,
)

from utils import StringRef

Expand Down
8 changes: 7 additions & 1 deletion stdlib/test/builtin/test_string_literal.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@
# ===----------------------------------------------------------------------=== #
# RUN: %mojo -debug-level full %s

from testing import *
from testing import (
assert_equal,
assert_not_equal,
assert_true,
assert_false,
assert_raises,
)


def test_basics():
Expand Down
2 changes: 1 addition & 1 deletion stdlib/test/builtin/test_stringref.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# ===----------------------------------------------------------------------=== #
# RUN: %mojo -debug-level full %s

from testing import *
from testing import assert_equal, assert_raises

from utils import StringRef

Expand Down
2 changes: 1 addition & 1 deletion stdlib/test/collections/test_dict.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ from collections import Optional
from collections.dict import Dict, KeyElement

from test_utils import CopyCounter
from testing import *
from testing import assert_equal, assert_false, assert_raises


def test_dict_construction():
Expand Down
2 changes: 1 addition & 1 deletion stdlib/test/collections/test_list.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from collections import List

from test_utils import CopyCounter, MoveCounter
from testing import *
from testing import assert_equal


def test_mojo_issue_698():
Expand Down
2 changes: 1 addition & 1 deletion stdlib/test/collections/test_optional.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from collections.optional import Optional, OptionalReg

from testing import *
from testing import assert_true, assert_false, assert_equal


def test_basic():
Expand Down
2 changes: 1 addition & 1 deletion stdlib/test/collections/test_set.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from collections.set import Set

from testing import *
from testing import assert_raises, assert_true, assert_false


fn assert_equal[T: EqualityComparable](lhs: T, rhs: T) raises:
Expand Down
2 changes: 1 addition & 1 deletion stdlib/test/collections/test_vector.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from collections.vector import InlinedFixedVector

from test_utils import MoveCounter
from testing import *
from testing import assert_equal


def test_inlined_fixed_vector():
Expand Down
2 changes: 1 addition & 1 deletion stdlib/test/memory/test_anypointer.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from memory.anypointer import AnyPointer
from test_utils import MoveCounter
from testing import *
from testing import assert_equal, assert_not_equal, assert_true


struct MoveOnlyType(Movable):
Expand Down
2 changes: 1 addition & 1 deletion stdlib/test/memory/test_arc.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from collections import List

from memory._arc import Arc
from testing import *
from testing import assert_equal, assert_false, assert_true


def test_basic():
Expand Down
2 changes: 1 addition & 1 deletion stdlib/test/os/path/test_exists.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from os.path import exists, lexists
from pathlib import Path, cwd

from testing import *
from testing import assert_true, assert_false


def main():
Expand Down
2 changes: 1 addition & 1 deletion stdlib/test/os/path/test_isdir.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from os.path import isdir
from pathlib import Path, cwd

from testing import *
from testing import assert_true, assert_false


def main():
Expand Down
2 changes: 1 addition & 1 deletion stdlib/test/os/path/test_isfile.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from os.path import isfile
from pathlib import Path

from testing import *
from testing import assert_true, assert_false


def main():
Expand Down
2 changes: 1 addition & 1 deletion stdlib/test/os/path/test_islink.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ from os.path import isdir, islink
from pathlib import Path
from sys.param_env import env_get_string

from testing import *
from testing import assert_true, assert_false

alias TEMP_DIR = env_get_string["TEMP_DIR"]()

Expand Down
4 changes: 2 additions & 2 deletions stdlib/test/os/test_listdir.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
# ===----------------------------------------------------------------------=== #
# RUN: %mojo -debug-level full %s

from os import *
from os import listdir
from pathlib import Path

from testing import *
from testing import assert_true


def test_listdir():
Expand Down
4 changes: 2 additions & 2 deletions stdlib/test/os/test_stat.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
# ===----------------------------------------------------------------------=== #
# RUN: %mojo -debug-level full %s

from os import *
from os import stat
from stat import S_ISREG

from testing import *
from testing import assert_not_equal, assert_true


def main():
Expand Down
4 changes: 2 additions & 2 deletions stdlib/test/pathlib/test_pathlib.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
# REQUIRES: !windows
# RUN: %mojo -debug-level full -D TEMP_FILE=%t %s

from pathlib import *
from pathlib import cwd, Path, DIR_SEPARATOR
from sys.param_env import env_get_string

from testing import *
from testing import assert_true, assert_false, assert_equal, assert_not_equal

alias TEMP_FILE = env_get_string["TEMP_FILE"]()

Expand Down
2 changes: 1 addition & 1 deletion stdlib/test/test_utils/__init__.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
#
# ===----------------------------------------------------------------------=== #

from .test_utils import *
from .test_utils import libm_call
from .types import CopyCounter, MoveCounter, MoveOnly
2 changes: 1 addition & 1 deletion stdlib/test/utils/test_variant.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from sys.ffi import _get_global

from memory.unsafe import Pointer
from testing import *
from testing import assert_equal, assert_false, assert_true

from utils.variant import Variant

Expand Down

0 comments on commit 6a9cd0a

Please sign in to comment.