test_path_utils.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # -*- coding:utf-8 -*-
  2. import os
  3. from dw_base.datax.path_utils import job_name_from_ini, json_output_path, log_path
  4. def test_job_name_from_ini_absolute():
  5. assert job_name_from_ini(
  6. '/home/bigdata/release/poyee-data-warehouse/tests/integration/datax/hive_import/app_user_cert_info.ini'
  7. ) == 'app_user_cert_info'
  8. def test_job_name_from_ini_relative():
  9. assert job_name_from_ini('jobs/raw/usr/xxx.ini') == 'xxx'
  10. def test_job_name_from_ini_no_ext():
  11. assert job_name_from_ini('xxx') == 'xxx'
  12. def test_json_output_path_flat():
  13. out = json_output_path(
  14. '/opt/release/poyee-data-warehouse',
  15. 'tests/integration/datax/hive_import/app_user_cert_info.ini',
  16. )
  17. assert os.path.normpath(out) == os.path.normpath(
  18. '/opt/release/poyee-data-warehouse/conf/datax-json/app_user_cert_info.json'
  19. )
  20. def test_json_output_path_with_dates():
  21. out = json_output_path(
  22. '/opt/release/poyee-data-warehouse',
  23. 'tests/integration/datax/hive_import/app_user_cert_info.ini',
  24. '20260311', '20260312',
  25. )
  26. assert os.path.normpath(out) == os.path.normpath(
  27. '/opt/release/poyee-data-warehouse/conf/datax-json/app_user_cert_info_20260311_20260312.json'
  28. )
  29. def test_json_output_path_only_start_falls_back():
  30. # 只传 start 不传 stop(半填),按文档约定退回无后缀格式(任一为空都视作缺省)
  31. out = json_output_path(
  32. '/opt/release/poyee-data-warehouse',
  33. 'tests/integration/datax/hive_import/app_user_cert_info.ini',
  34. '20260311', None,
  35. )
  36. assert os.path.normpath(out) == os.path.normpath(
  37. '/opt/release/poyee-data-warehouse/conf/datax-json/app_user_cert_info.json'
  38. )
  39. def test_log_path_template():
  40. out = log_path('/home/bigdata/log', 'datax', '20260422', 'app_user_cert_info')
  41. assert os.path.normpath(out) == os.path.normpath(
  42. '/home/bigdata/log/datax/20260422/app_user_cert_info.log'
  43. )