Skip to content

V2 compability tests #1555

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added tests/unit/v2/__init__.py
Empty file.
4 changes: 4 additions & 0 deletions tests/unit/v2/samples/simple.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
TensorFlow(entry_point="foo.py")
sagemaker.tensorflow.TensorFlow()
m = MXNet()
sagemaker.mxnet.MXNet()
13 changes: 13 additions & 0 deletions tests/unit/v2/test_framework_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import unittest
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can delete this file



class FrameworkVersion(unittest.TestCase):
def setUp(self) -> None:
pass

def test_something(self):
self.assertEqual(True, False)


if __name__ == '__main__':
unittest.main()
32 changes: 32 additions & 0 deletions tests/unit/v2/test_transformer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import ast
import unittest

from tests.unit.v2.utils import get_sample_file
from tools.compatibility.v2.ast_transformer import ASTTransformer
import pasta


class TransformerTest(unittest.TestCase):
def setUp(self) -> None:
self.transformer_class = ASTTransformer()

def test_simple_transform(self):
sample = get_sample_file('simple.txt')
rewrite = self.transformer_class.visit(
ast.parse(
sample
)
)

expected = """TensorFlow(entry_point='foo.py', framework_version='1.11.0')
sagemaker.tensorflow.TensorFlow(framework_version='1.11.0')
m = MXNet(framework_version='1.2.0')
sagemaker.mxnet.MXNet(framework_version='1.2.0')\n"""

self.assertEqual(pasta.dump(rewrite), expected)


if __name__ == '__main__':
unittest.main()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we use pytest, so as long as a function name starts with "test", it is run as part of the test suite



9 changes: 9 additions & 0 deletions tests/unit/v2/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from os.path import join

SAMPLES_DIRECTORY = "/Users/owahab/Desktop/personal/sagemaker-python-sdk/tests/unit/v2/samples/"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can either move the sample file to tests/data and use tests.unit.DATA_DIR or use a relative path



def get_sample_file(filename):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this is used in only one file (at least so far), I would leave it in test_transformer.py

file_path = join(SAMPLES_DIRECTORY, filename)
with open(file_path) as file_content:
return file_content.read()
2 changes: 1 addition & 1 deletion tools/compatibility/v2/ast_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import ast

from modifiers import framework_version
from tools.compatibility.v2.modifiers import framework_version

FUNCTION_CALL_MODIFIERS = [framework_version.FrameworkVersionEnforcer()]

Expand Down
2 changes: 1 addition & 1 deletion tools/compatibility/v2/modifiers/framework_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import ast

from modifiers.modifier import Modifier
from tools.compatibility.v2.modifiers.modifier import Modifier

FRAMEWORK_DEFAULTS = {
"Chainer": "4.1.0",
Expand Down