nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: edgurgel/mimic
Pull request #14 (2020-01-14 15:42:38)

Adds `Mimic.mode/0` for exposing the current mode
Related to https://github.com/edgurgel/mimic/issues/13, adds a `Mimic.mode/0` function for exposing the current mode.

jmnsf: @jimsynz done, thanks for having a look.
edgurgel: Thanks, @jmnsf & @jimsynz !

Patch:
diff --git a/lib/mimic.ex b/lib/mimic.ex
index 5feeeea..e83968c 100644
--- a/lib/mimic.ex
+++ b/lib/mimic.ex
@@ -418,6 +418,13 @@ defmodule Mimic do
     :ok
   end
 
+  @doc "Returns the current mode (`:global` or `:private`)"
+  @spec mode() :: :private | :global
+  def mode do
+    Server.get_mode()
+    |> validate_server_response("Couldn't get the current mode.")
+  end
+
   defp raise_if_not_copied!(module) do
     unless function_exported?(module, :__mimic_info__, 0) do
       raise ArgumentError,
diff --git a/lib/mimic/server.ex b/lib/mimic/server.ex
index 14903e4..e4b7462 100644
--- a/lib/mimic/server.ex
+++ b/lib/mimic/server.ex
@@ -50,6 +50,10 @@ defmodule Mimic.Server do
     GenServer.call(__MODULE__, :set_private_mode)
   end
 
+  def get_mode do
+    GenServer.call(__MODULE__, :get_mode)
+  end
+
   def exit(pid) do
     GenServer.cast(__MODULE__, {:exit, pid})
   end
@@ -265,6 +269,10 @@ defmodule Mimic.Server do
     {:reply, :ok, do_set_private_mode(state)}
   end
 
+  def handle_call(:get_mode, _from, state) do
+    {:reply, {:ok, state.mode}, state}
+  end
+
   def handle_call({:allow, module, owner_pid, allowed_pid}, _from, state = %State{mode: :private}) do
     case :ets.lookup(__MODULE__, {owner_pid, module}) do
       [{{^owner_pid, ^module}}] ->


Test patch:
diff --git a/test/mimic_test.exs b/test/mimic_test.exs
index 3f47a18..f697efb 100644
--- a/test/mimic_test.exs
+++ b/test/mimic_test.exs
@@ -728,6 +728,22 @@ defmodule Mimic.Test do
     end
   end
 
+  describe "mode/0 global mode" do
+    setup :set_mimic_global
+
+    test "returns :global" do
+      assert Mimic.mode() == :global
+    end
+  end
+
+  describe "mode/0 private mode" do
+    setup :set_mimic_private
+
+    test "returns :private" do
+      assert Mimic.mode() == :private
+    end
+  end
+
   describe "behaviours" do
     test "copies behaviour attributes" do
       behaviours =