text:
try:
    import mock
except ImportError:
    import unittest.mock as mock
import unittest

import django
from django.contrib.admin.models import LogEntry, CHANGE, DELETION
from django.contrib.admin.sites import AdminSite
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Permission
from waffle import get_waffle_flag_model
from waffle.admin import (FlagAdmin, SwitchAdmin, InformativeManyToManyRawIdWidget, enable_for_all,
                          disable_for_all, delete_individually, enable_switches, disable_switches)
from waffle.models import Switch
from waffle.tests.base import TestCase

django_version = tuple(int(d) for d in django.get_version().split("."))

class FakeSuperUser:
    def has_perm(self, perm):
        return True

class FakeRequest:
    def __init__(self):
        self.GET = {}
        self.user = get_user_model().objects.create(username="test1")

Flag = get_waffle_flag_model()

skip_if_admin_permissions_not_available = \
    unittest.skipIf(django_version < (2, 1, 0), "Feature not available")

class FlagAdminTests(TestCase):
    def setUp(self):
        self.site = AdminSite()
        self.flag_admin = FlagAdmin(Flag, self.site)

    def test_informative_widget(self):
        request = mock.Mock()
        request.has_perm = lambda self, perm: True
        form = self.flag_admin.get_form(request)()
        user_widget = form.fields["users"].widget

        self.assertIsInstance(user_widget, InformativeManyToManyRawIdWidget)
        user1 = get_user_model().objects.create(username="test1")
        user2 = get_user_model().objects.create(username="test2")
        self.assertIn("(test1, test2)",
                      user_widget.render("users", [user1.pk, user2.pk]))

    def test_enable_for_all(self):
        f1 = Flag.objects.create(name="flag1", everyone=False)

        request = FakeRequest()
        enable_for_all(None, request, Flag.objects.all())

        f1.refresh_from_db()
        self.assertTrue(f1.everyone)
        log_entry = LogEntry.objects.get(user=request.user)
        self.assertEqual(log_entry.action_flag, CHANGE)
        self.assertEqual(log_entry.object_repr, "flag1 on")

    def test_disable_for_all(self):
        f1 = Flag.objects.create(name="flag1", everyone=True)

        request = FakeRequest()
        disable_for_all(None, request, Flag.objects.all())

        f1.refresh_from_db()
        self.assertFalse(f1.everyone)
        log_entry = LogEntry.objects.get(user=request.user)
        self.assertEqual(log_entry.action_flag, CHANGE)
        self.assertEqual(log_entry.object_repr, "flag1 off")

    def test_delete_individually(self):
        Flag.objects.create(name="flag1", everyone=True)

        request = FakeRequest()
        delete_individually(None, request, Flag.objects.all())

        self.assertIsNone(Flag.objects.first())
        log_entry = LogEntry.objects.get(user=request.user)
        self.assertEqual(log_entry.action_flag, DELETION)

    @skip_if_admin_permissions_not_available
    def test_flag_no_actions_without_permissions(self):
        request = FakeRequest()
        actions = self.flag_admin.get_actions(request)

        self.assertEqual(actions.keys(), set())

    @skip_if_admin_permissions_not_available
    def test_flag_action_change(self):
        request = FakeRequest()
        request.user.user_permissions.add(Permission.objects.get(codename="change_flag"))
        actions = self.flag_admin.get_actions(request)

        self.assertEqual(actions.keys(), {"enable_for_all", "disable_for_all"})

    @skip_if_admin_permissions_not_available
    def test_flag_action_delete(self):
        request = FakeRequest()
        request.user.user_permissions.add(Permission.objects.get(codename="delete_flag"))
        actions = self.flag_admin.get_actions(request)

        self.assertEqual(actions.keys(), {"delete_individually"})

class SwitchAdminTests(TestCase):
    def setUp(self):
        self.site = AdminSite()
        self.switch_admin = SwitchAdmin(Switch, self.site)

    def test_enable_switches(self):
        s1 = Switch.objects.create(name="switch1", active=False)

        request = FakeRequest()
        enable_switches(None, request, Switch.objects.all())

        s1.refresh_from_db()
        self.assertTrue(s1.active)
        log_entry = LogEntry.objects.get(user=request.user)
        self.assertEqual(log_entry.action_flag, CHANGE)
        self.assertEqual(log_entry.object_repr, "switch1 on")

    def test_disable_switches(self):
        s1 = Switch.objects.create(name="switch1", active=True)

        request = FakeRequest()
        disable_switches(None, request, Switch.objects.all())

        s1.refresh_from_db()
        self.assertFalse(s1.active)
        log_entry = LogEntry.objects.get(user=request.user)
        self.assertEqual(log_entry.action_flag, CHANGE)
        self.assertEqual(log_entry.object_repr, "switch1 off")

    @skip_if_admin_permissions_not_available
    def test_switch_no_actions_without_permissions(self):
        request = FakeRequest()
        actions = self.switch_admin.get_actions(request)

        self.assertEqual(actions.keys(), set())

    @skip_if_admin_permissions_not_available
    def test_switch_action_change(self):
        request = FakeRequest()
        request.user.user_permissions.add(Permission.objects.get(codename="change_switch"))
        actions = self.switch_admin.get_actions(request)

        self.assertEqual(actions.keys(), {"enable_switches", "disable_switches"})

    @skip_if_admin_permissions_not_available
    def test_switch_action_delete(self):
        request = FakeRequest()
        request.user.user_permissions.add(Permission.objects.get(codename="delete_switch"))
        actions = self.switch_admin.get_actions(request)

        self.assertEqual(actions.keys(), {"delete_individually"})


text:
![Screenshot](https://raw.githubusercontent.com/aldelaro5/Dolphin-memory-engine/master/Docs/screenshot.png)

A RAM search specifically designed to search, track, and edit the emulated memory of [the Dolphin emulator](https://github.com/dolphin-emu/dolphin) at runtime. The primary goal is to make research, tool-assisted speedruns, and reverse engineering of GameCube & Wii games more convenient and easier than with the alternative solution, Cheat Engine. Its name is derived from Cheat Engine to symbolize that.

The GUI has been designed with convenience in mind, without disrupting the performance of the emulation. Qt 5 is used to help accomplish this.

For binary releases of this program, refer to [the "releases" page](https://github.com/aldelaro5/Dolphin-memory-engine/releases) on [the Github repository](https://github.com/aldelaro5/Dolphin-memory-engine).

## System requirements
Any x86_64 based system should theoretically work, however, please note that Mac OS is currently _not_ supported. Additionally, 32-bit x86 based systems are unsupported as Dolphin does not support them either. (Support for them was dropped a while ago.)

You absolutely need to have Dolphin running ***and*** _have the emulation started_ for this program to be of any use. As such, your system needs to meet Dolphin's [system requirements](https://github.com/dolphin-emu/dolphin#system-requirements). Additionally, have at least 250 MB of memory free.

On Linux, you need to install the Qt 5 package(s) for your respective distribution.

## How to Build
### Microsoft Windows
> *You will need Microsoft Visual Studio 2015 or 2017 with Visual C++ installed. Previous versions may work but are untested. The solution works best with VS2017, but with a small adjustment, it is possible to have VS2015 work.*

Before proceeding, make sure you have initialized the Qt submodule by running the command `git submodule update --init` at the repository's root. The files should appear at the `Externals\Qt` directory.

Once this is done, open Visual Studio and open the solution located in the `Source` directory. If you are using Visual Studio 2017, this is all you need to do, simply select the build configuration and build the solution. If you are using Visual Studio 2015 however, you may have to change the toolset of the project to the one that comes with Visual Studio 2015. To do so, right click on the project from the Solution Explorer and click properties. From there, change the "Platform Toolset" to the one that you have installed. Please note that this will change the settings in the `vcxproj` file so if you plan to submit a Pull Request, make sure to not stage this change.

### Linux
> _You will need CMake and Qt 5. Please refer to your distribution's documentation for specific instructions on how to install them if necessary._

To build for your system, simply run the following commands from the `Source` directory:

	mkdir build && cd build
	cmake ..
	make

The compiled binaries should be appear in the directory named `build`.

## General usage
First, open Dolphin and start a game, then run this program. Make sure that it reports that the Wii-only extra memory is present for Wii games and absent for GameCube games.

>_Exclusive to the Wii, this is an extra region of memory added as part of the enhancements from the earlier GameCube hardware. Consequently, the presence of this extra memory affects what is considered a valid watch address, as well as what areas of memory the scanner will look though._

If the hooking process is successful, the UI should be enabled, otherwise, you will need to click the hook button before the program can be of any use.

Once hooked, you can do scans just like Cheat Engine as well as manage your watch list. You can save and load your watch list to disk by using the file menu. The watch list files are in JSON and can be manually edited in the text editor of your choice.

If the program unhooks itself from Dolphin, it means a read/write operation failed, likely caused by the emulation halting in some way. Just boot a game again to solve this; your watch list and scan will be retained if this happens.

Finally, the program also includes a memory viewer which shows an hexadecimal view and an ASCII view of the memory. Simply click on the corresponding button or right click on a watch to browse the memory using the memory viewer.

## License
This program is licensed under the MIT license which grants you the permission to do  anything you wish to with the software, as long as you preserve all copyright notices. (See the file LICENSE for the legal text.)

redpajama_set_name: RedPajamaGithub


text:
A Story
=======

Analyze :math:`z=e^{-1/x^2}` (infinite derivatives, all 0 at 0)

Construct w=0+z function

Construct h=w*w(1-x)

Construct :math:`s=\int w`

Construct n, normalized s

Construct :math:`f_\epsilon`, fast step function

Construct :math:`t_\epsilon`, roughly f*f(1-x)

Tell the story


text:
/* eslint-env mocha */

import sinon from 'sinon';
import { expect } from 'chai';
import $ from 'jquery';
import { ErrorHandler, Notification } from '/client/imports/modules';
import CollectionHelper from '/client/imports/ui/collection/helper';
import { Communicator } from '/client/imports/facades';

describe('CollectionHelper', () => {
  beforeEach(() => {
    sinon.stub($.prototype, 'modal');
    sinon.stub(ErrorHandler, 'showMeteorFuncError');
    sinon.stub(Notification, 'success');
  });

  afterEach(() => {
    $.prototype.modal.restore();
    ErrorHandler.showMeteorFuncError.restore();
    Notification.success.restore();
  });

  it('executeCommand invalid param', () => {
    // prepare
    sinon.stub(Communicator, 'call');

    // execute
    CollectionHelper.executeCommand();

    // verify
    expect(Communicator.call.callCount).to.equal(0);
    expect($.prototype.modal.callCount).to.equal(0);

    // cleanup
    Communicator.call.restore();
  });

  it('executeCommand valid param & no modal & communicator yields success', () => {
    // prepare
    const command = 'testCommand';
    sinon.stub(Communicator, 'call').yieldsTo('callback', null, {});

    // execute
    CollectionHelper.executeCommand(command);

    // verify
    expect(Communicator.call.callCount).to.equal(1);
    expect(Communicator.call.calledWithMatch({
      methodName: 'command',
      args: { command },
      callback: sinon.match.func
    })).to.equal(true);
    expect(ErrorHandler.showMeteorFuncError.callCount).to.equal(0);
    expect(Notification.success.callCount).to.equal(1);
    expect(Notification.success.calledWithExactly('saved-successfully')).to.equal(true);
    expect($.prototype.modal.callCount).to.equal(0);

    // cleanup
    Communicator.call.restore();
  });

  it('executeCommand valid param & modal & communicator yields success', () => {
    // prepare
    const command = 'testCommand';
    const modalSelector = 'testModal';
    sinon.stub(Communicator, 'call').yieldsTo('callback', null, {});

    // execute
    CollectionHelper.executeCommand(command, modalSelector);

    // verify
    expect(Communicator.call.callCount).to.equal(1);
    expect(Communicator.call.calledWithMatch({
      methodName: 'command',
      args: { command },
      callback: sinon.match.func
    })).to.equal(true);
    expect(ErrorHandler.showMeteorFuncError.callCount).to.equal(0);
    expect(Notification.success.callCount).to.equal(1);
    expect(Notification.success.calledWithExactly('saved-successfully')).to.equal(true);
    expect($.prototype.modal.callCount).to.equal(1);
    expect($.prototype.modal.calledWithExactly('hide')).to.equal(true);
    expect($.prototype.modal.getCall(0).thisValue.selector).to.equal('#testModal');

    // cleanup
    Communicator.call.restore();
  });

  it('executeCommand valid param & communicator yields error', () => {
    // prepare
    const command = 'testCommand';
    const error = { error: '1009' };
    sinon.stub(Communicator, 'call').yieldsTo('callback', error, {});

    // execute
    CollectionHelper.executeCommand(command, 'tttt');

    // verify
    expect(Communicator.call.callCount).to.equal(1);
    expect(Communicator.call.calledWithMatch({
      methodName: 'command',
      args: { command },
      callback: sinon.match.func
    })).to.equal(true);
    expect(ErrorHandler.showMeteorFuncError.callCount).to.equal(1);
    expect(ErrorHandler.showMeteorFuncError.calledWithExactly(error, {})).to.equal(true);
    expect(Notification.success.callCount).to.equal(0);
    expect($.prototype.modal.callCount).to.equal(0);

    // cleanup
    Communicator.call.restore();
  });

  it('executeCommand valid param & communicator yields error (1)', () => {
    // prepare
    const command = 'testCommand';
    const error = { error: '1009' };
    sinon.stub(Communicator, 'call').yieldsTo('callback', null, error);

    // execute
    CollectionHelper.executeCommand(command, 'tttt');

    // verify
    expect(Communicator.call.callCount).to.equal(1);
    expect(Communicator.call.calledWithMatch({
      methodName: 'command',
      args: { command },
      callback: sinon.match.func
    })).to.equal(true);
    expect(ErrorHandler.showMeteorFuncError.callCount).to.equal(1);
    expect(ErrorHandler.showMeteorFuncError.calledWithExactly(null, error)).to.equal(true);
    expect(Notification.success.callCount).to.equal(0);
    expect($.prototype.modal.callCount).to.equal(0);

    // cleanup
    Communicator.call.restore();
  });
});