# Path: picatrix/lib/testlib.py
# class InteractiveTest:
#   def _init_shell(cls):
#   def get_shell(cls) -> TerminalInteractiveShell:
#   def run_and_compare(cls, code: Text, expected_return: Any):


from picatrix.lib import testlib
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Tests for the pixatrix state object."""


def test_getting_last_magic():
  """Test running a magic."""
  ip = testlib.InteractiveTest.get_shell()
  ip.run_cell(raw_cell='from picatrix.magics import common')
  res = ip.run_cell(raw_cell='common.picatrixmagics("")')
  output_df = res.result
  #output_df = ip.run_line_magic(magic_name='picatrixmagics', line='')

  code = (
      'df = common.last_output("")\n'
      'names = list(df.name.unique())\n'
      'sorted(names)')

  names = list(output_df['name'].unique())

# Path: picatrix/lib/testlib.py
# class InteractiveTest:
#   def _init_shell(cls):
#   def get_shell(cls) -> TerminalInteractiveShell:
#   def run_and_compare(cls, code: Text, expected_return: Any):


# Path: picatrix/lib/state_test.py
from picatrix.lib import testlib

# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Tests for the pixatrix state object."""


def test_getting_last_magic():
  """Test running a magic."""
  ip = testlib.InteractiveTest.get_shell()
  ip.run_cell(raw_cell='from picatrix.magics import common')
  res = ip.run_cell(raw_cell='common.picatrixmagics("")')
  output_df = res.result
  #output_df = ip.run_line_magic(magic_name='picatrixmagics', line='')

  code = (
      'df = common.last_output("")\n'
      'names = list(df.name.unique())\n'
      'sorted(names)')

  names = list(output_df['name'].unique())

  testlib.InteractiveTest.run_and_compare(code, expected_return=sorted(names))