Coverage for tests/test_snake_case_converter.py: 100%

6 statements  

« prev     ^ index     » next       coverage.py v7.10.6, created at 2025-09-01 18:15 +0800

1""" 

2Tests for logging configuration functionality. 

3""" 

4from ss_utils_safe_python import to_snake_case 

5 

6def test_snake_case_converter(): 

7 """Test the snake_case converter with various report section examples.""" 

8 test_cases = [ 

9 # Basic cases 

10 ("Executive Summary", "executive_summary"), 

11 ("Introduction", "introduction"), 

12 # CamelCase 

13 ("FinancialPerformance", "financial_performance"), 

14 ("CompanyOverview", "company_overview"), 

15 ("RiskAssessment", "risk_assessment"), 

16 # Title Case with spaces 

17 ("Market Analysis", "market_analysis"), 

18 ("Business Strategy", "business_strategy"), 

19 ("Corporate Governance", "corporate_governance"), 

20 # UPPER CASE 

21 ("FINANCIAL STATEMENTS", "financial_statements"), 

22 ("RISK FACTORS", "risk_factors"), 

23 # kebab-case 

24 ("sustainability-report", "sustainability_report"), 

25 ("cash-flow-analysis", "cash_flow_analysis"), 

26 # Mixed formats 

27 ("Section 1.2: Company Overview", "section_1_2_company_overview"), 

28 ("Part A - Financial Results", "part_a_financial_results"), 

29 ("Chapter 3: Market Position", "chapter_3_market_position"), 

30 # Special characters 

31 ("ESG & Sustainability", "esg_sustainability"), 

32 ("P&L Statement", "p_l_statement"), 

33 ("Q1/Q2 Performance", "q1_q2_performance"), 

34 ("Cost-Benefit Analysis", "cost_benefit_analysis"), 

35 # Numbers and mixed 

36 ("2023 Annual Report", "2023_annual_report"), 

37 ("Q4 2023 Results", "q4_2023_results"), 

38 ("5-Year Plan", "5_year_plan"), 

39 # Complex real-world examples 

40 ("Environmental, Social & Governance (ESG) Report", "environmental_social_governance_esg_report"), 

41 ("Management's Discussion & Analysis", "management_s_discussion_analysis"), 

42 ("Notes to Financial Statements", "notes_to_financial_statements"), 

43 ("Independent Auditor's Report", "independent_auditor_s_report"), 

44 # Edge cases 

45 ("", ""), 

46 (" ", ""), 

47 ("___", ""), 

48 ("A", "a"), 

49 ("ABC", "abc"), 

50 ("a_b_c", "a_b_c"), # Already snake_case 

51 ] 

52 

53 for input_text, expected in test_cases: 

54 result = to_snake_case(input_text) 

55 assert result == expected, f"Failed for '{input_text}': got '{result}', expected '{expected}'"