github.phpd.cn/thought-machine/please@v12.2.0+incompatible/test/python_rules/data_dep_only_test.py (about)

     1  """Test that data for a test isn't also packed into the .pex."""
     2  
     3  import os
     4  import subprocess
     5  import unittest
     6  import zipfile
     7  
     8  
     9  class DataDepTest(unittest.TestCase):
    10  
    11      def test_cannot_import_data_dep(self):
    12          """Test that the file didn't get packed into the pex."""
    13          import __main__ as pex_main
    14          with zipfile.ZipFile(pex_main.PEX) as zf:
    15              with self.assertRaises(KeyError):
    16                  zf.getinfo('test/python_rules/data_dep.pex')
    17              with self.assertRaises(KeyError):
    18                  zf.getinfo('test/python_rules/data_dep.py')
    19  
    20      def test_can_run_data_dep(self):
    21          """Test that we can also invoke the .pex directly as a data dependency."""
    22          output = subprocess.check_output(['test/python_rules/data_dep.pex'])
    23          self.assertEqual('42', output.strip().decode('utf-8'))