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

Unit testing with mock data #196

Open
vbandaru opened this issue Jan 7, 2025 · 2 comments
Open

Unit testing with mock data #196

vbandaru opened this issue Jan 7, 2025 · 2 comments

Comments

@vbandaru
Copy link

vbandaru commented Jan 7, 2025

seeking guidance on how to mock screen at 1 and 2 so that we can unit test. is it possible to set whole screen text as internal state to tnz/ati so that i can extract multiple fields.

def extract_data(input):
    ati = Ati()

    try:
      ati.set("TRACE", "ALL") # Turn tracing on
      ati.set("LOGDEST", "demo.log") # Log file name
      ati.set("DISPLAY", "HOST") # HOST screens will be logged
    
      ati.set("SESSION_HOST", "999.999.999.999") 
      ati.set("SESSION_PORT", "23") 
      ati.set("SESSION", "A") 
      ati.wait(5)
    
       ati.send("logon applid=jdoe")
       ati.wait(1)
       ati.send("PROG1[enter]")
       ati.wait(lambda : ati.scrhas("MAIN SCREEN"))  ## i would like to mock this   #####1 
       field1= ati.extract(50, (23,5))
       field2= ati.extract(51, (23,5))
       :
       : 
       : more fields on main screen

       ati.send("MENU1[enter]")
       ati.wait(lambda : ati.scrhas("MENU 1 SCREEN"))  ## i would like to mock this   #####2
       field3= ati.extract(22, (23,5))
       field4= ati.extract(23, (23,5))
       : 
       :
      return {"a": feild1,  "b": field2, "c": field3, "d": field4}

      finally:
         ## ati.send("[pa2]") # alt-home to logoff
         ati.drop("SESSION")

      return {}
}
@vbandaru
Copy link
Author

vbandaru commented Jan 8, 2025

@najohnsn

@najohnsn
Copy link
Member

najohnsn commented Jan 8, 2025

Check out test/test_tnz.py in this repo. It creates some mock screens to test some tnz functions. It is on the tnz level, not the ati level, but couldn use ati.get_tnz() to get the tnz object to mock up the screen and then use ati functions to validate your code. Of course, you'd have to have the ability to create some session to mock up. Unfortunately, mocking up screens in this way requires some fairly intimate knowledge of tnz and 3270 protocols.

Somewhat related to #154 ... it seems like it would be useful to record a screen in order to generate your mock screen.

Other than writing your own 3270 application/server... that's the best there is for now.

Maybe the easiest thing to be helpful would be some dummy session that isn't really connected to anything - it would just be an unprotected screen that you could use send() to write character data to it?

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

No branches or pull requests

2 participants