Skip to content
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

DM-17932: Validate object type when reading objects from pickle #16

Merged
merged 1 commit into from Apr 2, 2019

Conversation

andy-slac
Copy link
Collaborator

Trivial change to the code. Also adds less trivial unit test for these
checks to validate validation. CmdLineFwk unit tests will be expanded
later with more tests for other methods (some will need reasonable
registry contents).



@contextlib.contextmanager
def makeTmpFile():
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason you chose to make your own Context manager instead of using tempfile.TemporaryFile ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The reason is that I need the name of the file and not file object. It could potentially be done with NamedTemporaryFile but it still needs additional code to close the file, so I prefer old-fashioned mkstemp instead in a separate context manager.

pickle.dump({}, pickleFile)
args = _makeArgs(pipeline=tmpname)
with self.assertRaises(TypeError):
pipeline = fwk.makePipeline(taskFactory, args)
Copy link
Contributor

Choose a reason for hiding this comment

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

Small nitpick, but a statement assigning this to a variable seems needless for this and the test below.


# make empty graph and store it in a file
qgraph = QuantumGraph()
with open(tmpname, "wb") as pickleFile:
Copy link
Contributor

Choose a reason for hiding this comment

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

Would this be better to do like the test above where you using the save the graph by using the save_graph argument to _makeArgs?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The CmdLineFwk.makeGraph() method cannot make empty QGraph, and to make non-empty one it needs butler which we do not have yet implemented for unit tests. So the only way to save QGraph to a pickle file now is to make an instance manually and write it ourselves. That is simple enough for this unit test.

Trivial change to the code. Also adds less trivial unit test for these
checks to validate validation. CmdLineFwk unit tests will be expanded
later with more tests for other methods (some will need reasonable
registry contents).
@andy-slac andy-slac merged commit 1490f67 into master Apr 2, 2019
@timj timj deleted the tickets/DM-17932 branch April 23, 2020 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants