Skip to content

Commit

Permalink
Merge pull request #236 from neptune-ai/wip/pj/fix-noop-backend
Browse files Browse the repository at this point in the history
Fixes "neptune.init() throws exceptions with combination of ipython and offline-mode"
  • Loading branch information
PiotrJander authored Jun 16, 2020
2 parents fc0f13f + ead3dd0 commit 355b220
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,7 @@ venv.bak/

# Vim
*.swp

# VS Code
.history
.vscode
8 changes: 4 additions & 4 deletions neptune/internal/backends/offline_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,14 @@ def download_data(self, project, path, destination):

class NoopObject(object):

def __getattribute__(self, item):
return NoopObject()
def __getattr__(self, item):
return self

def __call__(self, *args, **kwargs):
return NoopObject()
return self

def __enter__(self):
return NoopObject()
return self

def __exit__(self, exc_type, exc_val, exc_tb):
pass
55 changes: 55 additions & 0 deletions tests/neptune/internal/backends/test_noop_object.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#
# Copyright (c) 2019, Neptune Labs Sp. z o.o.
#
# 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
#
# http://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.
#

import unittest

from neptune.internal.backends.offline_backend import NoopObject

class TestHostedNeptuneObject(unittest.TestCase):

def test_builtin_fields_not_overriden(self):
# given
objectUnderTest = NoopObject()

# then
self.assertIsInstance(objectUnderTest.__class__, type)

def test_attributes_fall_back_on_getattr(self):
# given
objectUnderTest = NoopObject()
some_value = 42

# then
self.assertEqual(objectUnderTest.foo, objectUnderTest)
self.assertEqual(objectUnderTest.bar(some_value), objectUnderTest)

def test_noop_object_callable(self):
# given
objectUnderTest = NoopObject()
some_value = 42

# then
self.assertEqual(objectUnderTest(some_value), objectUnderTest)

def test_noop_object_context_manager(self):
# given
objectUnderTest = NoopObject()

# when
with objectUnderTest as e:

# then
e(42)

0 comments on commit 355b220

Please sign in to comment.