From f27b43a19e9a5ed8c8a6d46216b75d5d5f332555 Mon Sep 17 00:00:00 2001 From: gabrieldemarmiesse Date: Sun, 12 May 2024 14:52:01 +0000 Subject: [PATCH] Fix all pre-commit Signed-off-by: gabrieldemarmiesse --- stdlib/src/os/env.mojo | 12 ++++ stdlib/src/os/os.mojo | 5 ++ stdlib/src/testing/testing.mojo | 92 ++++++++++++++++++++++++++++++ stdlib/test/builtin/test_hash.mojo | 1 + 4 files changed, 110 insertions(+) diff --git a/stdlib/src/os/env.mojo b/stdlib/src/os/env.mojo index cc793b786..0246cd70b 100644 --- a/stdlib/src/os/env.mojo +++ b/stdlib/src/os/env.mojo @@ -53,6 +53,18 @@ fn setenv(name: String, value: String, overwrite: Bool = True) -> Bool: fn getenv(name: String) -> String: + """Returns the value of the given environment variable. + + Constraints: + The function only works on macOS or Linux and returns an empty string + otherwise. The default is an empty string. + + Args: + name: The name of the environment variable. + + Returns: + The value of the environment variable. + """ return getenv(name, "") diff --git a/stdlib/src/os/os.mojo b/stdlib/src/os/os.mojo index 73936845f..8ea75cdef 100644 --- a/stdlib/src/os/os.mojo +++ b/stdlib/src/os/os.mojo @@ -187,6 +187,11 @@ struct _DirHandle: # listdir # ===----------------------------------------------------------------------=== # fn listdir() raises -> List[String]: + """Gets the list of entries contained in the empty path. + + Returns: + Returns the list of entries in the path provided. + """ return listdir("") diff --git a/stdlib/src/testing/testing.mojo b/stdlib/src/testing/testing.mojo index 407da845c..115092d2d 100644 --- a/stdlib/src/testing/testing.mojo +++ b/stdlib/src/testing/testing.mojo @@ -73,6 +73,15 @@ fn _assert_error[T: Stringable](msg: T, loc: _SourceLocation) -> String: @always_inline fn assert_true(val: Bool) raises: + """Asserts that the input value is True. If it is not then an + Error is raised. + + Args: + val: The value to assert to be True. + + Raises: + An Error with the provided message if assert fails and `None` otherwise. + """ if not val: raise _assert_error( "condition was unexpectedly False", __call_location() @@ -97,6 +106,15 @@ fn assert_true(val: Bool, msg: String) raises: @always_inline fn assert_false(val: Bool) raises: + """Asserts that the input value is False. If it is not then an Error is + raised. + + Args: + val: The value to assert to be False. + + Raises: + An Error with the provided message if assert fails and `None` otherwise. + """ if val: raise _assert_error( "condition was unexpectedly True", __call_location() @@ -128,6 +146,19 @@ trait Testable(EqualityComparable, Stringable): @always_inline fn assert_equal[T: Testable](lhs: T, rhs: T) raises: + """Asserts that the input values are equal. If it is not then an Error + is raised. + + Parameters: + T: A Testable type. + + Args: + lhs: The lhs of the equality. + rhs: The rhs of the equality. + + Raises: + An Error with the provided message if assert fails and `None` otherwise. + """ if lhs != rhs: raise _assert_equal_error(str(lhs), str(rhs), "", __call_location()) @@ -154,6 +185,16 @@ fn assert_equal[T: Testable](lhs: T, rhs: T, msg: String) raises: @always_inline fn assert_equal(lhs: String, rhs: String) raises: + """Asserts that the input values are equal. If it is not then an Error + is raised. + + Args: + lhs: The lhs of the equality. + rhs: The rhs of the equality. + + Raises: + An Error with the provided message if assert fails and `None` otherwise. + """ assert_equal(lhs, rhs, "") @@ -179,6 +220,20 @@ fn assert_equal(lhs: String, rhs: String, msg: String) raises: fn assert_equal[ type: DType, size: Int ](lhs: SIMD[type, size], rhs: SIMD[type, size]) raises: + """Asserts that the input values are equal. If it is not then an + Error is raised. + + Parameters: + type: The dtype of the left- and right-hand-side SIMD vectors. + size: The width of the left- and right-hand-side SIMD vectors. + + Args: + lhs: The lhs of the equality. + rhs: The rhs of the equality. + + Raises: + An Error with the provided message if assert fails and `None` otherwise. + """ assert_equal(lhs, rhs, "") @@ -209,6 +264,19 @@ fn assert_equal[ @always_inline("nodebug") fn assert_not_equal[T: Testable](lhs: T, rhs: T) raises: + """Asserts that the input values are not equal. If it is not then an + Error is raised. + + Parameters: + T: A Testable type. + + Args: + lhs: The lhs of the inequality. + rhs: The rhs of the inequality. + + Raises: + An Error with the provided message if assert fails and `None` otherwise. + """ assert_not_equal(lhs, rhs, "") @@ -236,6 +304,16 @@ fn assert_not_equal[T: Testable](lhs: T, rhs: T, msg: String) raises: @always_inline("nodebug") fn assert_not_equal(lhs: String, rhs: String) raises: + """Asserts that the input values are not equal. If it is not then an + an Error is raised. + + Args: + lhs: The lhs of the inequality. + rhs: The rhs of the inequality. + + Raises: + An Error with the provided message if assert fails and `None` otherwise. + """ assert_not_equal(lhs, rhs, "") @@ -260,6 +338,20 @@ fn assert_not_equal(lhs: String, rhs: String, msg: String) raises: fn assert_not_equal[ type: DType, size: Int ](lhs: SIMD[type, size], rhs: SIMD[type, size]) raises: + """Asserts that the input values are not equal. If it is not then an + Error is raised. + + Parameters: + type: The dtype of the left- and right-hand-side SIMD vectors. + size: The width of the left- and right-hand-side SIMD vectors. + + Args: + lhs: The lhs of the inequality. + rhs: The rhs of the inequality. + + Raises: + An Error with the provided message if assert fails and `None` otherwise. + """ assert_not_equal(lhs, rhs, "") diff --git a/stdlib/test/builtin/test_hash.mojo b/stdlib/test/builtin/test_hash.mojo index 76ccae8dc..562001bab 100644 --- a/stdlib/test/builtin/test_hash.mojo +++ b/stdlib/test/builtin/test_hash.mojo @@ -146,6 +146,7 @@ def test_hash_string_struct(): assert_not_equal(hash(a), hash(c)) assert_not_equal(hash(b), hash(c)) + def main(): test_hash_byte_array() test_hash_simd()